From: Moritz Bunkus Date: Thu, 6 Sep 2012 08:00:17 +0000 (+0200) Subject: SL::Locale::String-Klasse für verzögerte Übersetzung hinzugefügt X-Git-Tag: release-3.0.0beta1~249^2~1 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=87b0de4c742e6032bcb6bf8750b1d8144e1a9860;p=kivitendo-erp.git SL::Locale::String-Klasse für verzögerte Übersetzung hinzugefügt --- diff --git a/SL/Controller/Helper/Sorted.pm b/SL/Controller/Helper/Sorted.pm index 8699f00c7..c9e577911 100644 --- a/SL/Controller/Helper/Sorted.pm +++ b/SL/Controller/Helper/Sorted.pm @@ -22,7 +22,7 @@ sub make_sorted { while (my ($column, $spec) = each %specs) { next if $column =~ m/^[A-Z_]+$/; - $spec = $specs{$column} = { title => $spec } if !ref $spec; + $spec = $specs{$column} = { title => $spec } if (ref($spec) || '') ne 'HASH'; $spec->{model} ||= $specs{MODEL}; $spec->{model_column} ||= $column; diff --git a/SL/Locale.pm b/SL/Locale.pm index 5016900fe..8fa37805d 100644 --- a/SL/Locale.pm +++ b/SL/Locale.pm @@ -214,6 +214,8 @@ sub text { my $self = shift; my $text = shift; + return $text->translated if (ref($text) || '') eq 'SL::Locale::String'; + if ($self->{texts}->{$text}) { $text = $self->{iconv}->convert($self->{texts}->{$text}); } else { diff --git a/SL/Locale/String.pm b/SL/Locale/String.pm new file mode 100644 index 000000000..42ceb22a6 --- /dev/null +++ b/SL/Locale/String.pm @@ -0,0 +1,120 @@ +package SL::Locale::String; + +use strict; + +use parent qw(Rose::Object Exporter); + +use Rose::Object::MakeMethods::Generic ( + scalar => [ qw(untranslated) ], +); + +our @EXPORT = qw(t8); + +use overload '""' => \&translated; + +sub translated { + my ($self) = @_; + return $::locale ? $::locale->text($self->untranslated) : $self->untranslated; +} + +sub t8 { + my $string = $_[ ref($_[0]) || ($_[0] eq 'SL::Locale::String') ? 1 : 0 ]; + return SL::Locale::String->new(untranslated => $string); +} + +1; +__END__ + +=pod + +=encoding utf8 + +=head1 NAME + +SL::Locale::String - Helper class for translating strings at a later +date (e.g. use at compile time, actual translation during execution +time) + +=head1 SYNOPSIS + + use SL::Locale::String; + + use SL::Controller::Helper::Sorted; + + __PACKAGE__->make_sorted( + ... + qty => { title => t8("Quantity") }, + ); + +=head1 OVERVIEW + +Every string that should be translated must be recognized by our +translation helper script C