From ed5d76f36e6ecf59d68ac71fca5a4a35480f78de Mon Sep 17 00:00:00 2001 From: vti Date: Sun, 9 Nov 2008 15:29:35 +0100 Subject: [PATCH] Version 0.03 - RDBO_I18N_LANG as a new $ENV variable to hold default language - Fix wrong column selection in Helpers --- Rose-DBx-Object-I18N/Changes | 4 ++++ Rose-DBx-Object-I18N/lib/Rose/DBx/Object/I18N.pm | 4 ++-- .../lib/Rose/DBx/Object/I18N/Helpers.pm | 18 ++++++++---------- Rose-DBx-Object-I18N/t/00load.t | 9 --------- Rose-DBx-Object-I18N/t/00use.t | 7 +++++++ Rose-DBx-Object-I18N/t/available-translations.t | 2 +- Rose-DBx-Object-I18N/t/load.t | 8 +++++--- Rose-DBx-Object-I18N/t/manager.t | 4 ++-- 8 files changed, 29 insertions(+), 27 deletions(-) delete mode 100644 Rose-DBx-Object-I18N/t/00load.t create mode 100644 Rose-DBx-Object-I18N/t/00use.t diff --git a/Rose-DBx-Object-I18N/Changes b/Rose-DBx-Object-I18N/Changes index e713200..6465ca4 100644 --- a/Rose-DBx-Object-I18N/Changes +++ b/Rose-DBx-Object-I18N/Changes @@ -1,5 +1,9 @@ Revision history for Rose-DBx-Object-I18N +0.03 2008-11-09 00:00:00 + - RDBO_I18N_LANG as a new $ENV variable to hold default language + - Fix wrong column selection in Helpers + 0.02 2008-11-08 00:00:00 Pod coverage testing on demand. diff --git a/Rose-DBx-Object-I18N/lib/Rose/DBx/Object/I18N.pm b/Rose-DBx-Object-I18N/lib/Rose/DBx/Object/I18N.pm index 6b0c3e6..d119db2 100644 --- a/Rose-DBx-Object-I18N/lib/Rose/DBx/Object/I18N.pm +++ b/Rose-DBx-Object-I18N/lib/Rose/DBx/Object/I18N.pm @@ -14,7 +14,7 @@ use Rose::DBx::Object::I18N::Helpers ':all'; our $Debug = 0; -our $VERSION = 0.01; +our $VERSION = 0.03; =head1 NAME @@ -416,7 +416,7 @@ sub update { =head2 load -When you want to load default language ($ENV{LANG} or original) just load as you +When you want to load default language ($ENV{RDBO_I18N_LANG} or original) just load as you always do: $u = User->new( id => 1 ); diff --git a/Rose-DBx-Object-I18N/lib/Rose/DBx/Object/I18N/Helpers.pm b/Rose-DBx-Object-I18N/lib/Rose/DBx/Object/I18N/Helpers.pm index f36973b..03d9281 100644 --- a/Rose-DBx-Object-I18N/lib/Rose/DBx/Object/I18N/Helpers.pm +++ b/Rose-DBx-Object-I18N/lib/Rose/DBx/Object/I18N/Helpers.pm @@ -6,20 +6,18 @@ use warnings; use Rose::Object::MixIn(); our @ISA = qw(Rose::Object::MixIn); -__PACKAGE__->export_tag( all => [ qw(i18n_language) ] ); +__PACKAGE__->export_tag(all => [qw(i18n_language)]); sub i18n_language { - my ( $self ) = @_; + my ($self) = @_; - my $lang; + my $lang = $ENV{RDBO_I18N_LANG}; - my $env_lang; - ( $env_lang ) = ( $ENV{ LANG } =~ m/^(..)(?:_..\.)?/ ) if $ENV{ LANG }; - - $lang = $env_lang; - - if ( !$lang && $self ) { - $lang = $self->can( 'orig_lang' ) ? $self->orig_lang : undef; + if (!$lang && $self) { + unless ( $self->can('object_class') ) { + my $i18n_lang_column = $self->_i18n_lang_column; + $lang = $self->$i18n_lang_column; + } } return $lang; diff --git a/Rose-DBx-Object-I18N/t/00load.t b/Rose-DBx-Object-I18N/t/00load.t deleted file mode 100644 index 64f742d..0000000 --- a/Rose-DBx-Object-I18N/t/00load.t +++ /dev/null @@ -1,9 +0,0 @@ -#!perl -T - -use Test::More tests => 1; - -BEGIN { - use_ok( 'Rose::DBx::Object::I18N' ); -} - -diag( "Testing Rose::DBx::Object::I18N $Rose::DBx::Object::I18N::VERSION, Perl $], $^X" ); diff --git a/Rose-DBx-Object-I18N/t/00use.t b/Rose-DBx-Object-I18N/t/00use.t new file mode 100644 index 0000000..9f0be65 --- /dev/null +++ b/Rose-DBx-Object-I18N/t/00use.t @@ -0,0 +1,7 @@ +#!perl -T + +use Test::More tests => 1; + +BEGIN { + use_ok( 'Rose::DBx::Object::I18N' ); +} diff --git a/Rose-DBx-Object-I18N/t/available-translations.t b/Rose-DBx-Object-I18N/t/available-translations.t index fd6962e..57a1635 100644 --- a/Rose-DBx-Object-I18N/t/available-translations.t +++ b/Rose-DBx-Object-I18N/t/available-translations.t @@ -21,7 +21,7 @@ my $u = User->new( ); $u->save(); -$ENV{ LANG } = 'ru'; +$ENV{ RDBO_I18N_LANG } = 'ru'; $u = User->new( id => $u->id ); $u->load(); diff --git a/Rose-DBx-Object-I18N/t/load.t b/Rose-DBx-Object-I18N/t/load.t index af9478a..d9361fc 100644 --- a/Rose-DBx-Object-I18N/t/load.t +++ b/Rose-DBx-Object-I18N/t/load.t @@ -21,7 +21,7 @@ my $u = User->new( ); $u->save(); -$ENV{ LANG } = 'en'; +$ENV{ RDBO_I18N_LANG } = 'en'; $u = User->new( id => $u->id ); $u->load(); @@ -32,12 +32,14 @@ is( $u->i18n( 'ru' )->lang, 'ru' ); $u = User->new( id => $u->id ); $u->load(); -$ENV{ LANG } = 'ru'; + +$ENV{ RDBO_I18N_LANG } = 'ru'; is( $u->i18n->lang, 'ru' ); $u = User->new( id => $u->id ); $u->load(); -$ENV{ LANG } = 'en'; + +$ENV{ RDBO_I18N_LANG } = 'en'; is( $u->i18n->lang, 'en' ); $u->delete( cascade => 1 ); diff --git a/Rose-DBx-Object-I18N/t/manager.t b/Rose-DBx-Object-I18N/t/manager.t index d7e17c1..2daf0c5 100644 --- a/Rose-DBx-Object-I18N/t/manager.t +++ b/Rose-DBx-Object-I18N/t/manager.t @@ -29,7 +29,7 @@ my $u2 = User->new( ); $u2->save(); -$ENV{ LANG } = undef; +$ENV{ RDBO_I18N_LANG } = undef; my $users = User::Manager->get_objects(); @@ -39,7 +39,7 @@ is( $users->[ 0 ]->i18n_is_loaded(), 0 ); is( $users->[ 0 ]->i18n->lang, 'en' ); is( $users->[ 1 ]->i18n->lang, 'ru' ); -$ENV{ LANG } = 'en'; +$ENV{ RDBO_I18N_LANG } = 'en'; $users = User::Manager->get_objects(); -- 2.11.4.GIT