Skip to content

Commit

Permalink
Item14601: ease usage of a local WebLexicon
Browse files Browse the repository at this point in the history
don't require it to be registered explicitly in the WebPreferences
  • Loading branch information
MichaelDaum committed Jan 12, 2018
1 parent d152a75 commit 66fe194
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
15 changes: 11 additions & 4 deletions data/System/MultiLingualPlugin.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" comment="" date="1500461121" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" comment="" date="1515758221" format="1.1" version="1"}%
---+!! %TOPIC%
%FORMFIELD{"Description"}%

Expand Down Expand Up @@ -62,10 +62,16 @@ switch to different content maintained somewhere else in your wiki:
To separate the application of translated strings from their translation you might specify a lexicon, either

* using the =lexicon= parameter to =%TRANSLATE= or
* using the =CONTENT_LEXICON= preference variable or
* using the =WEBLEXICON= preference variable or
* using the <nop>WebLexicon topic in the current web

The lexicon is a topic holding =%META:LEXICON= records as produced by the Foswiki:Extensions/MetaDataPlugin
Multiple lexicons can be specified in the =WEBLEXICON= preference variable separated by commas. Entries
are looked up in the lexicons with the given precedence, that is an entry is returned as found in the first lexicon on the list.

A <nop>WebLexicon topic in the current web will allways take highest precedence over all other lexicons listed in =WEBLEXICON=.
It is not required to list it explicitly in the =WEBLEXICON= prefernce.

Each lexicon is a topic holding =%META:LEXICON= records as produced by the Foswiki:Extensions/MetaDataPlugin
and specified in the [[LexiconForm]] shipped with this plugin.

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

---++ Change History
| 12 Jan 2018 | don't require a local <nop>WebLexicon to be registered |
| 13 Sep 2017 | better handling of enabled languages; added Greek flag to mapping; suppress Locale::Codes' error reporting to stderr |
| 16 Jan 2017 | fixed crash translating strings with certain bracket links |
| 02 Sep 2016 | added support for <nop>WebLexicon |
Expand All @@ -219,7 +226,7 @@ in his/her browser or the value of ={DefaultLanguage}= as configured to this plu
%META:FIELD{name="Release" title="Release" value="%25$RELEASE%25"}%
%META:FIELD{name="Description" title="Description" value="%25$SHORTDESCRIPTION%25"}%
%META:FIELD{name="Repository" title="Repository" value="https://github.com/foswiki/%25TOPIC%25"}%
%META:FIELD{name="Copyright" title="Copyright" value="&copy; 2013-2017 Michael Daum http://michaeldaumconsulting.com"}%
%META:FIELD{name="Copyright" title="Copyright" value="&copy; 2013-2018 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="Home" title="Home" value="Foswiki:Extensions/%25TOPIC%25"}%
%META:FIELD{name="Support" title="Support" value="Foswiki:Support/%25TOPIC%25"}%
6 changes: 3 additions & 3 deletions lib/Foswiki/Plugins/MultiLingualPlugin.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# MultiLingualPlugin is Copyright (C) 2013-2017 Michael Daum http://michaeldaumconsulting.com
# MultiLingualPlugin is Copyright (C) 2013-2018 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand All @@ -21,8 +21,8 @@ use warnings;
use Foswiki::Func ();
use Foswiki::Plugins ();

our $VERSION = '3.10';
our $RELEASE = '13 Sep 2017';
our $VERSION = '4.00';
our $RELEASE = '12 Jan 2018';
our $SHORTDESCRIPTION = 'Support for a multi lingual Foswiki';
our $NO_PREFS_IN_TOPIC = 1;
our $core;
Expand Down
19 changes: 11 additions & 8 deletions lib/Foswiki/Plugins/MultiLingualPlugin/Core.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# MultiLingualPlugin is Copyright (C) 2013-2017 Michael Daum http://michaeldaumconsulting.com
# MultiLingualPlugin is Copyright (C) 2013-2018 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -179,19 +179,22 @@ sub TRANSLATE {

$theWeb = $params->{web} if defined $params->{web};

my $lexiconTopics = $params->{lexicon};
$lexiconTopics = Foswiki::Func::getPreferencesValue("CONTENT_LEXICON", $theWeb)
if !defined($lexiconTopics) || $lexiconTopics eq '';
my $lexiconTopics = $params->{lexicon} || '';

$lexiconTopics = Foswiki::Func::getPreferencesValue("WEBLEXICON", $theWeb)
|| Foswiki::Func::getPreferencesValue("CONTENT_LEXICON", $theWeb)
|| ''
if $lexiconTopics eq '';

$lexiconTopics = 'WebLexicon'
if (!defined($lexiconTopics) || $lexiconTopics eq '')
&& Foswiki::Func::topicExists($theWeb, 'WebLexicon');
# add local lexicon if it exists
$lexiconTopics = 'WebLexicon, '.$lexiconTopics if Foswiki::Func::topicExists($theWeb, 'WebLexicon');

if (defined $lexiconTopics && $lexiconTopics ne "") {
if ($lexiconTopics ne '') {
$lexiconTopics = Foswiki::Func::expandCommonVariables($lexiconTopics, $theTopic, $theWeb);
my $lexiconWeb = $theWeb;
my $languageName = getLanguageOfCode($langCode);
foreach my $lexiconTopic (split(/\s*,\s*/, $lexiconTopics)) {
next if $lexiconTopic eq "";
($lexiconWeb, $lexiconTopic) = Foswiki::Func::normalizeWebTopicName($lexiconWeb, $lexiconTopic);
my $entry = $this->getLexiconEntry($lexiconWeb, $lexiconTopic, $text);
my $translation;
Expand Down

0 comments on commit 66fe194

Please sign in to comment.