From 66fe19469dc03b62a2123b597b6793240956d2be Mon Sep 17 00:00:00 2001 From: MichaelDaum Date: Fri, 12 Jan 2018 12:57:15 +0100 Subject: [PATCH] Item14601: ease usage of a local WebLexicon don't require it to be registered explicitly in the WebPreferences --- data/System/MultiLingualPlugin.txt | 15 +++++++++++---- lib/Foswiki/Plugins/MultiLingualPlugin.pm | 6 +++--- .../Plugins/MultiLingualPlugin/Core.pm | 19 +++++++++++-------- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/data/System/MultiLingualPlugin.txt b/data/System/MultiLingualPlugin.txt index 89a7874..9d51e3b 100644 --- a/data/System/MultiLingualPlugin.txt +++ b/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"}% @@ -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 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 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 @@ -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 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 WebLexicon | @@ -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="© 2013-2017 Michael Daum http://michaeldaumconsulting.com"}% +%META:FIELD{name="Copyright" title="Copyright" value="© 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"}% diff --git a/lib/Foswiki/Plugins/MultiLingualPlugin.pm b/lib/Foswiki/Plugins/MultiLingualPlugin.pm index ce81129..ed7ca77 100644 --- a/lib/Foswiki/Plugins/MultiLingualPlugin.pm +++ b/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 @@ -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; diff --git a/lib/Foswiki/Plugins/MultiLingualPlugin/Core.pm b/lib/Foswiki/Plugins/MultiLingualPlugin/Core.pm index 5127aa4..b11ba2c 100644 --- a/lib/Foswiki/Plugins/MultiLingualPlugin/Core.pm +++ b/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 @@ -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;