Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Item14081: implement argN parameter
... to keep %TRANSLATE compatible with %MAKETEXT as a drop-in-replacement.
  • Loading branch information
MichaelDaum committed May 31, 2016
1 parent c864b3e commit 8ff92a3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion data/System/LexiconForm.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" comment="" date="1418744195" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" comment="" date="1464687321" format="1.1" version="1"}%
%META:TOPICPARENT{name="MultiLingualPlugin"}%
---+!! %TOPIC%

Expand Down
22 changes: 12 additions & 10 deletions data/System/MultiLingualPlugin.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" comment="" date="1418744195" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" comment="" date="1464687321" format="1.1" version="1"}%
---+!! %TOPIC%
%FORMFIELD{"Description"}%

Expand Down Expand Up @@ -75,9 +75,10 @@ This is the work horse returning a string based on the selected target language.
| *Parameter* | *Description* | *Default* |
| ="string"= | (required) the source string to be translated; it serves as a lookup key into the lexicon | |
| =language="<lang-code>"= | the language code of the target language | |
| =lexicon=="<topic-name>"= | the topic holding the lexicon meta data | |
| =lexicon="<topic-name>"= | the topic holding the lexicon meta data | |
| =args="arg1, arg2, ..."= | arguments to be inserted into the translated string | |
| =splitargs="<separator>"= | expression to separate items in the =args= list | =\s*,\s*= |
| =arg&lt;N>="..."= | alternative way to specify arguments, e.g. =%<nop>TRANSLATE{"... " arg1="..." arg2="..." ...}%= | |

A =string= as well as a translation may contain placeholder such as =[_1]=, =[_2]=, =[_3]= ... to refer to the
first/second/third/... argument in the =args= list.
Expand Down Expand Up @@ -124,8 +125,8 @@ It iterates over the list of given languages and returns information for each la
| =selection= | depicts a language in the list to be "selected" which activates the =$marker= string as defined below | |
| =marker= | string to be inserted into the =format= when the current language matches the =selection= | =selected="selected"= |
| =include= | regular expression a language must match for it to be included in the output | |
| =exclude | regular expression a language must _not_ match for it to be included in the output | |
| =sort= |
| =exclude= | regular expression a language must _not_ match for it to be included in the output | |
| =sort= | sorting order of output; can be =on=, =off=, =code=, =country=, =name=, =label= or =language= | =language= |

Each language has got a list of properties that can be referred to in =format= and =sort=.

Expand Down Expand Up @@ -202,6 +203,7 @@ in his/her browser or the value of ={DefaultLanguage}= as configured to this plu
%$DEPENDENCIES%

---++ Change History
| 31 May 2016 | added =arg&lt;N>= way of specifying arguments to =%TRANSLATE= |
| 8 Mar 2016 | fixed error using latest Locale::Country |
| 17 Jul 2015 | fixed detection of CONTENT_LEXICON and extraction of correct string for a given language |
| 16 Dec 2014 | added =$label_name= and =$language_name= to ease select boxes |
Expand All @@ -210,11 +212,11 @@ in his/her browser or the value of ={DefaultLanguage}= as configured to this plu

%META:FORM{name="PackageForm"}%
%META:FIELD{name="Author" title="Author" value="Michael Daum"}%
%META:FIELD{name="Copyright" title="Copyright" value="&copy; 2013-2016 Michael Daum http://michaeldaumconsulting.com"}%
%META:FIELD{name="Version" title="Version" value="%25$VERSION%25"}%
%META:FIELD{name="Release" title="Release" value="%25$RELEASE%25"}%
%META:FIELD{name="Description" title="Description" value="%25$SHORTDESCRIPTION%25"}%
%META:FIELD{name="Home" title="Home" value="Foswiki:Extensions/%TOPIC%"}%
%META:FIELD{name="Repository" title="Repository" value="https://github.com/foswiki/%25TOPIC%25"}%
%META:FIELD{name="Copyright" title="Copyright" value="&copy; 2013-2016 Michael Daum http://michaeldaumconsulting.com"}%
%META:FIELD{name="License" title="License" value="[[http://www.gnu.org/licenses/gpl.html][GPL (Gnu General Public License)]]"}%
%META:FIELD{name="Release" title="Release" value="%$RELEASE%"}%
%META:FIELD{name="Repository" title="Repository" value="https://github.com/foswiki/%TOPIC%"}%
%META:FIELD{name="Support" title="Support" value="Foswiki:Support/%TOPIC%"}%
%META:FIELD{name="Version" title="Version" value="%$VERSION%"}%
%META:FIELD{name="Home" title="Home" value="Foswiki:Extensions/%25TOPIC%25"}%
%META:FIELD{name="Support" title="Support" value="Foswiki:Support/%25TOPIC%25"}%
4 changes: 2 additions & 2 deletions lib/Foswiki/Plugins/MultiLingualPlugin.pm
Expand Up @@ -21,8 +21,8 @@ use warnings;
use Foswiki::Func ();
use Foswiki::Plugins ();

our $VERSION = '2.20';
our $RELEASE = '08 Mar 2016';
our $VERSION = '2.30';
our $RELEASE = '31 May 2016';
our $SHORTDESCRIPTION = 'Support for a multi lingual Foswiki';
our $NO_PREFS_IN_TOPIC = 1;
our $core;
Expand Down
7 changes: 7 additions & 0 deletions lib/Foswiki/Plugins/MultiLingualPlugin/Core.pm
Expand Up @@ -203,6 +203,13 @@ sub TRANSLATE {
my $split = $params->{splitargs} || '\s*,\s*';
my @args = split($split, $args);

# gather enumerated args arg1, arg2, ...
foreach my $key (keys %$params) {
if ($key =~ /^arg(\d+)$/) {
$args[$1] = $params->{$key};
}
}

push @args, '' for (0...100); # fill up args in case there are more placeholders in text

my $error;
Expand Down

0 comments on commit 8ff92a3

Please sign in to comment.