Skip to content

Commit

Permalink
Item13158: ease creation of a lang selection box
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed Dec 16, 2014
1 parent 34aa9d4 commit e67c601
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion data/System/LexiconForm.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" comment="reprev" date="1378986032" format="1.1" reprev="2" version="2"}%
%META:TOPICINFO{author="ProjectContributor" comment="" date="1418744195" format="1.1" version="1"}%
%META:TOPICPARENT{name="MultiLingualPlugin"}%
---+!! %TOPIC%

Expand Down
18 changes: 17 additions & 1 deletion data/System/MultiLingualPlugin.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" comment="reprev" date="1378985817" format="1.1" reprev="4" version="4"}%
%META:TOPICINFO{author="ProjectContributor" comment="" date="1418744195" format="1.1" version="1"}%
---+!! %TOPIC%
%SHORTDESCRIPTION%

Expand Down Expand Up @@ -139,9 +139,11 @@ Each language has got a list of properties that can be referred to in =format= a
This information can be used as tokens in a =format= string, such as

* =$language=
* =$language_name=
* =$name= (or =$langname= ... provided for backwards compatibility)
* =$code= (or =$langtag= ... provided for backwards compatibility)
* =$label=
* =$label_name=
* =$icon=, =$icon(<size>)= (the html img with a country flag; use the second form to render a flag in different sizes)
* =$country=

Expand All @@ -160,6 +162,7 @@ This is recommended for any new Foswiki installation. See Foswiki:Extensions/Cha

---++ Examples

---+++ All languages
Render a full table of all known languages:

%LANGUAGES{
Expand All @@ -171,6 +174,18 @@ Render a full table of all known languages:
sort="language"
}%

---+++ Select language

<select name="lang">
%LANGUAGES{
format="<option value='$code' $marker>$label_name</option>"
marker="selected='selected'"
selection="%LANGUAGE%"
separator="$n "
sort="label"
}%
</select

---++ Installation Instructions

%$INSTALL_INSTRUCTIONS%
Expand All @@ -186,6 +201,7 @@ Render a full table of all known languages:
| Release: | %$RELEASE% |
| Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 16 Dec 2014 | added =$label_name= and =$language_name= to ease select boxes |
| 1 Nov 2013 | initial release |
| Dependencies: | %$DEPENDENCIES% |
| Home page: | Foswiki:Extensions/%TOPIC% |
Expand Down
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 = '1.01';
our $RELEASE = '1.01';
our $VERSION = '2.00';
our $RELEASE = '2.00';
our $SHORTDESCRIPTION = 'Support for a multi lingual Foswiki';
our $NO_PREFS_IN_TOPIC = 1;
our $core;
Expand Down
4 changes: 3 additions & 1 deletion lib/Foswiki/Plugins/MultiLingualPlugin/Core.pm
Expand Up @@ -180,7 +180,7 @@ sub TRANSLATE {
my $languageName = getLanguageOfCode($langCode);
if ($entry && $languageName) {
my $key = fieldTitle2FieldName("$languageName ($langCode)");
$text = $entry->{$key} if defined $entry->{$key} && $entry->{key} ne '';
$text = $entry->{$key} if defined $entry->{$key} && $entry->{$key} ne '';
}
}

Expand Down Expand Up @@ -277,6 +277,8 @@ sub LANGUAGES {
$item =~ s/\$icon(?:\((.*?)\))?/$this->getFlagImage($record->{code}, $1||16)/ge;
$item =~ s/\$name/$record->{name}/g;
$item =~ s/\$code/$record->{code}/g;
$item =~ s/\$label_name(?:\((.*?)\))?/$record->{label}.(($record->{label} eq $record->{name})?'':($1||' - ').$record->{name})/ge;
$item =~ s/\$language_name(?:\((.*?)\))?/$record->{language}.(($record->{language} eq $record->{name})?'':($1||' - ').$record->{name})/ge;
$item =~ s/\$language/$record->{language}/g;
$item =~ s/\$label/$record->{label}/g;
$item =~ s/\$country/$record->{country}/g;
Expand Down

0 comments on commit e67c601

Please sign in to comment.