Changeset 4517
- Timestamp:
- 07/21/09 16:08:35 (3 years ago)
- Location:
- trunk/TopicTranslationsPlugin
- Files:
-
- 6 added
- 2 deleted
- 3 moved
-
data/System (added)
-
data/System/TopicTranslationsPlugin.txt (moved) (moved from trunk/TopicTranslationsPlugin/data/TWiki/TopicTranslationsPlugin.txt) (12 diffs)
-
lib/Foswiki (added)
-
lib/Foswiki/Plugins (added)
-
lib/Foswiki/Plugins/TopicTranslationsPlugin (added)
-
lib/Foswiki/Plugins/TopicTranslationsPlugin.pm (moved) (moved from trunk/TopicTranslationsPlugin/lib/TWiki/Plugins/TopicTranslationsPlugin.pm) (19 diffs)
-
lib/Foswiki/Plugins/TopicTranslationsPlugin/DEPENDENCIES (added)
-
lib/Foswiki/Plugins/TopicTranslationsPlugin/MANIFEST (added)
-
lib/Foswiki/Plugins/TopicTranslationsPlugin/build.pl (moved) (moved from trunk/TopicTranslationsPlugin/lib/TWiki/Plugins/TopicTranslationsPlugin/build.pl) (1 diff)
-
lib/TWiki/Plugins/TopicTranslationsPlugin/DEPENDENCIES (deleted)
-
lib/TWiki/Plugins/TopicTranslationsPlugin/MANIFEST (deleted)
Legend:
- Unmodified
- Added
- Removed
-
trunk/TopicTranslationsPlugin/data/System/TopicTranslationsPlugin.txt
r2847 r4517 1 %META:TOPICINFO{author=" AntonioTerceiro" date="1128026733" format="1.0" version="1.1"}%1 %META:TOPICINFO{author="ProjectContributor" date="1128026733" format="1.0" version="1.1"}% 2 2 ---+!! !TopicTranslationsPlugin 3 3 … … 16 16 Each web that is going to use !TopicTranslationsPlugin must define a variable named 17 17 =%<nop/>TOPICTRANSLATIONS%=, which must contains a comma-delimited list of language 18 code. =%<nop/>TOPICTRANSLATIONS%= can be defined TWiki-wide, which means that those19 languages will be used for the entire TWiki installation. It can also be defined18 code. =%<nop/>TOPICTRANSLATIONS%= can be defined system-wide, which means that those 19 languages will be used for the entire site. It can also be defined 20 20 per user. If none of th above is set, the plugin setting for !TopicTranslationsPlugin 21 21 with the same name (=%<nop/>TOPICTRANSLATIONS%=) will be used as a default. … … 70 70 The language detected for the current topic (based on the current topic's name suffix). 71 71 72 ---+++ =%<nop/>CURRENTLANGUAGESUFFIX%= 73 74 The language suffix of the current topic (empty if the current topic is in the 75 default language, since the default language has not suffix). This is useful 76 in menus to create links to fixed topics in the current language. Example: 77 78 <verbatim> 79 <a href="%SCRIPTURL{view}%/%WEB%/SomeTopic%CURRENTLANGUAGESUFFIX%"></a> 80 </verbatim> 81 72 82 ---+++=%<nop/>DEFAULTLANGUAGE%= 73 83 … … 109 119 110 120 It's useful when used in conjuntcion with a view VIEW_TEMPLATE setting or some 111 similar way of making TWiki-editable custom layouts (like the obsolete112 TWiki:Main/FreeSkin), or even site-specific custom skins.121 similar way of making user-editable custom layouts (like the obsolete 122 [[TWiki:Main/FreeSkin][FreeSkin]]), or even site-specific custom skins. 113 123 114 124 %RED% __Warnings:__ %ENDCOLOR% … … 116 126 * This tag is a workaround for sites that want to display user-written 117 127 different translations of some text based on the current topic's language, 118 while TWiki does not provide a standard way to do that in its core (what 119 is mainly [[TWiki:Main/AntonioTerceiro][my]] fault). 128 while Foswiki does not provide a standard way to do that in its core. 120 129 * This tag is also somewhat conflicting with core's %<nop/>MAKETEXT{}%. The 121 difference is that MAKETEXT uses TWiki-detected language and 122 TRANSLATEMESSAGE uses !TopicTranslationsPlugin-detected language, which 123 may be different in some casse. 130 difference is that MAKETEXT uses system-detected language (e.g. detected 131 from the browser, or set explicitly by the user) and TRANSLATEMESSAGE uses 132 !TopicTranslationsPlugin-detected language (detected from the topic name), 133 which may be different in some casse. 124 134 125 135 ---++ Automatic Redirection … … 144 154 from =no=, =off= and =0=). 145 155 146 __Note:__ in TWiki:Codev/CairoRelease, to make this work you'll have to apply the 147 following patch to =TWiki/Func.pm= module (got from TWiki's Subversion repository): 156 <blockquote> 157 __Note:__ in older TWiki releases, such as TWiki:Codev/CairoRelease, to make 158 this work you'll have to apply the following patch to =TWiki/Func.pm= module 159 (got from TWiki's Subversion repository): 148 160 149 161 <verbatim> 150 --- /var/lib/twiki/lib/ TWiki/Func.pm 2005-07-02 13:33:46.893777128 -0300162 --- /var/lib/twiki/lib/Foswiki/Func.pm 2005-07-02 13:33:46.893777128 -0300 151 163 +++ Func.pm 2005-07-02 13:37:22.187047576 -0300 152 164 @@ -407,8 +407,9 @@ … … 163 175 # ========================= 164 176 </verbatim> 177 </blockquote> 165 178 166 179 ---++ Examples … … 193 206 ---++ Plugin Installation Instructions 194 207 195 __Note:__ You do not need to install anything on the browser to use this plugin. The following instructions are for the administrator who installs the plugin on the server where TWiki is running.208 __Note:__ You do not need to install anything on the browser to use this plugin. The following instructions are for the administrator who installs the plugin on the server where Foswiki is running. 196 209 197 210 * Download the ZIP file from the Plugin web (see below) … … 201 214 | ==data/System/%TOPIC%.txt,v== | Plugin topic repository | 202 215 | ==lib/Foswiki/Plugins/%TOPIC%.pm== | Plugin Perl module | 203 * (Dakar) Visit =configure= in your TWiki installation, and enable the plugin in the {Plugins} section.216 * Visit =configure= in your Foswiki installation, and enable the plugin in the {Plugins} section. 204 217 * Test if the installation was successful: 205 218 * see the examples [[#Examples][above]] … … 207 220 ---++ Plugin Info 208 221 209 | Plugin Author: | TWiki:Main.AntonioTerceiro |210 | Copyright: | © 2006, TWiki:Main.AntonioTerceiro |222 | Plugin Author: | Foswiki:Main.AntonioTerceiro | 223 | Copyright: | Copyright © 2005-2009, Foswiki:Main.AntonioTerceiro | 211 224 | License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) | 212 225 | Plugin Version: | 03 Jul 2005 (V1.003) | … … 220 233 | 02 Jul 2005 | Version =1.002=: major rewrite; documented all (or almost all :)) the code; added selection of available/missing translations; added =missingformat=; added support for custom topics (and webs) in <code>%<nop/>TRANSLATIONS%</code>; added automatic redirection for the "best" translation (detection via =I18N::AcceptLanguage=). | 221 234 | 19 Jun 2005: | Initial version: =1.001= | 222 | TWiki Dependency: | $TWiki::Plugins::VERSION 1.024 |235 | Foswiki Dependency: | $Foswiki::Plugins::VERSION 1.024 | 223 236 | CPAN Dependencies: | =I18N::AcceptLanguage= | 224 237 | Other Dependencies: | none | … … 229 242 __Related Topics:__ %SYSTEMWEB%.DefaultPreferences, %USERSWEB%.SitePreferences, [[%SYSTEMWEB%.Plugins][Plugins]] 230 243 231 -- TWiki:Main.AntonioTerceiro - 03 Jul 2005232 244 -- Foswiki:Main.AntonioTerceiro - 21 Jul 2009 245 -
trunk/TopicTranslationsPlugin/lib/Foswiki/Plugins/TopicTranslationsPlugin.pm
r1340 r4517 1 1 # Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/ 2 2 # 3 # Copyright (C) 2005 Antonio S. de A. Terceiro, asaterceiro@inf.ufrgs.br3 # Copyright (C) 2005-2009 Antonio Terceiro, terceiro@softwarelivre.org 4 4 # 5 5 # This program is free software; you can redistribute it and/or … … 15 15 16 16 # ========================= 17 package TWiki::Plugins::TopicTranslationsPlugin;17 package Foswiki::Plugins::TopicTranslationsPlugin; 18 18 19 19 # ========================= … … 30 30 use I18N::AcceptLanguage; 31 31 32 # This should always be $Rev$ so that TWiki can determine the checked-in32 # This should always be $Rev$ so that Foswiki can determine the checked-in 33 33 # status of the plugin. It is used by the build automation tools, so 34 34 # you should leave it alone. … … 47 47 48 48 # check for Plugins.pm versions 49 if( $ TWiki::Plugins::VERSION < 1.024 ) {50 TWiki::Func::writeWarning( "Version mismatch between $pluginName and Plugins.pm" );49 if( $Foswiki::Plugins::VERSION < 1.024 ) { 50 Foswiki::Func::writeWarning( "Version mismatch between $pluginName and Plugins.pm" ); 51 51 return 0; 52 52 } 53 53 54 54 # Get plugin debug flag 55 $debug = TWiki::Func::getPluginPreferencesFlag( "DEBUG" );55 $debug = Foswiki::Func::getPluginPreferencesFlag( "DEBUG" ); 56 56 57 57 # those should be preferably set in a per web basis. Defaults to the 58 58 # corresponding plugin setting (or "en" if someone messes with it) 59 my $trans = TWiki::Func::getPreferencesValue("TOPICTRANSLATIONS") || TWiki::Func::getPluginPreferencesValue("TOPICTRANSLATIONS") || "en";59 my $trans = Foswiki::Func::getPreferencesValue("TOPICTRANSLATIONS") || Foswiki::Func::getPluginPreferencesValue("TOPICTRANSLATIONS") || "en"; 60 60 @translations = split(/,\s*/,$trans); 61 $redirectMethod = TWiki::Func::getPreferencesValue("REDIRECTMETHOD") || TWiki::Func::getPluginPreferencesValue("REDIRECTMETHOD") || "http";62 $userLanguage = TWiki::Func::getPreferencesValue("LANGUAGE") || "en";61 $redirectMethod = Foswiki::Func::getPreferencesValue("REDIRECTMETHOD") || Foswiki::Func::getPluginPreferencesValue("REDIRECTMETHOD") || "http"; 62 $userLanguage = Foswiki::Func::getPreferencesValue("LANGUAGE") || "en"; 63 63 64 64 # first listed language is the default one: … … 74 74 75 75 # must I redirect to the best available translation? 76 my $mustRedirect = (! TWiki::Func::getPluginPreferencesFlag("DISABLE_AUTOMATIC_REDIRECTION"));76 my $mustRedirect = (! Foswiki::Func::getPluginPreferencesFlag("DISABLE_AUTOMATIC_REDIRECTION")); 77 77 checkRedirection() if $mustRedirect; 78 78 79 79 # Plugin correctly initialized 80 TWiki::Func::writeDebug( "- TWiki::Plugins::${pluginName}::initPlugin( $web.$topic ) is OK" ) if $debug;80 Foswiki::Func::writeDebug( "- Foswiki::Plugins::${pluginName}::initPlugin( $web.$topic ) is OK" ) if $debug; 81 81 return 1; 82 82 } … … 86 86 ### my ( $text, $topic, $web ) = @_; # do not uncomment, use $_[0], $_[1]... instead 87 87 88 TWiki::Func::writeDebug( "- ${pluginName}::beforeCommonTagsHandler( $_[2].$_[1] )" ) if $debug;88 Foswiki::Func::writeDebug( "- ${pluginName}::beforeCommonTagsHandler( $_[2].$_[1] )" ) if $debug; 89 89 90 90 # handle all INCLUDETRANSLATION tags: … … 96 96 ### my ( $text, $topic, $web ) = @_; # do not uncomment, use $_[0], $_[1]... instead 97 97 98 TWiki::Func::writeDebug( "- ${pluginName}::commonTagsHandler( $_[2].$_[1] )" ) if $debug;98 Foswiki::Func::writeDebug( "- ${pluginName}::commonTagsHandler( $_[2].$_[1] )" ) if $debug; 99 99 100 100 # handle our common tags: 101 101 $_[0] =~ s/%TRANSLATIONS({(.*?)})?%/&handleTranslations($2)/ge; 102 102 $_[0] =~ s/%CURRENTLANGUAGE%/¤tLanguage/ge; 103 $_[0] =~ s/%CURRENTLANGUAGESUFFIX%/¤tLanguageSuffix/ge; 103 104 $_[0] =~ s/%DEFAULTLANGUAGE%/$defaultLanguage/ge; 104 105 $_[0] =~ s/%BASETRANSLATION({(.*?)})?%/&handleBaseTranslation($2)/ge; … … 106 107 } 107 108 108 # transform a language code into a suitable suffix for TWiki topics,109 # by capitalizingthe first letter and all the others lowercase.109 # transform a language code into a suitable suffix for topics, by capitalizing 110 # the first letter and all the others lowercase. 110 111 # Examples: 111 112 # pt-br -> Ptbr EN -> En … … 146 147 } 147 148 149 # returns the current language suffix, or '' (empty string) if the current 150 # language is the default one 151 sub currentLanguageSuffix { 152 my $lang = currentLanguage(); 153 return ($lang eq $defaultLanguage) ? '' : normalizeLanguageName($lang); 154 } 155 148 156 # list the translations of the current topic (or to that one passed as an 149 157 # argument). Depending on the arguments to the %TRANSLATIONS% tag, many options … … 157 165 158 166 # format for the items: 159 my $format = TWiki::Func::extractNameValuePair($params, "format") || "[[\$web.\$translation][\$language]]";160 my $missingFormat = TWiki::Func::extractNameValuePair($params, "missingformat") || $format;167 my $format = Foswiki::Func::extractNameValuePair($params, "format") || "[[\$web.\$translation][\$language]]"; 168 my $missingFormat = Foswiki::Func::extractNameValuePair($params, "missingformat") || $format; 161 169 162 170 # other stuff: 163 my $userSeparator = TWiki::Func::extractNameValuePair($params, "separator") || " ";171 my $userSeparator = Foswiki::Func::extractNameValuePair($params, "separator") || " "; 164 172 165 173 # 166 my $theTopic = TWiki::Func::extractNameValuePair($params) || TWiki::Func::extractNameValuePair($params,"topic") || $topic;174 my $theTopic = Foswiki::Func::extractNameValuePair($params) || Foswiki::Func::extractNameValuePair($params,"topic") || $topic; 167 175 my $theWeb; 168 176 if ($theTopic =~ m/^([^.]+)\.([^.]+)/) { … … 176 184 177 185 # find out which translations we must list: 178 my $which = TWiki::Func::extractNameValuePair($params, "which") || "all";186 my $which = Foswiki::Func::extractNameValuePair($params, "which") || "all"; 179 187 my @whichTranslations; 180 188 if ($which eq "available") { … … 202 210 203 211 # wheter to use the format for available translations or for missing ones: 204 my $result = ( TWiki::Func::topicExists($web, $translationTopic))?($format):($missingFormat);212 my $result = (Foswiki::Func::topicExists($web, $translationTopic))?($format):($missingFormat); 205 213 206 214 # substitute the variables: … … 220 228 my $theLang = currentLanguage(); 221 229 222 my $theTopic = TWiki::Func::extractNameValuePair($params);230 my $theTopic = Foswiki::Func::extractNameValuePair($params); 223 231 my $theWeb; 224 232 if ($theTopic =~ m/^([^.]+)\.([^.]+)/) { … … 236 244 237 245 # undef is ok, meaning current revision: 238 my $theRev = TWiki::Func::extractNameValuePair($params, "rev");246 my $theRev = Foswiki::Func::extractNameValuePair($params, "rev"); 239 247 240 248 my $args = "\"$theWeb.$theTopic\""; … … 268 276 my $script = $ENV{SCRIPT_NAME} || '/view'; 269 277 270 if (($script =~ m #/view(auth)?$#) and (! $ENV{QUERY_STRING})) {271 my $query = TWiki::Func::getCgiQuery();278 if (($script =~ m/\/view(auth)?$/) and (! $ENV{QUERY_STRING})) { 279 my $query = Foswiki::Func::getCgiQuery(); 272 280 273 281 # several checks 274 282 my $baseTopicName = findBaseTopicName(); 275 my $baseUrl = TWiki::Func::getViewUrl($web, $baseTopicName);276 my $editUrl = TWiki::Func::getScriptUrl($web, $baseTopicName, 'edit');283 my $baseUrl = Foswiki::Func::getViewUrl($web, $baseTopicName); 284 my $editUrl = Foswiki::Func::getScriptUrl($web, $baseTopicName, 'edit'); 277 285 my $origin = $query->referer() || ''; 278 286 … … 289 297 # actually do the redirect: 290 298 my $bestTranslationTopic = findBaseTopicName() . (($best eq $defaultLanguage)?'':(normalizeLanguageName($best))); 291 my $url = TWiki::Func::getViewUrl($web,$bestTranslationTopic);292 TWiki::Func::redirectCgiQuery($query, $url);299 my $url = Foswiki::Func::getViewUrl($web,$bestTranslationTopic); 300 Foswiki::Func::redirectCgiQuery($query, $url); 293 301 } 294 302 } … … 326 334 327 335 # is that translation available? 328 $exists = TWiki::Func::topicExists($web, $theTopic . $norm);336 $exists = Foswiki::Func::topicExists($web, $theTopic . $norm); 329 337 330 338 # what kind (available or not) are we looking for? … … 339 347 sub handleBaseTranslation { 340 348 my $params = shift; 341 my $myTopic = TWiki::Func::extractNameValuePair($params, "topic") || $topic;349 my $myTopic = Foswiki::Func::extractNameValuePair($params, "topic") || $topic; 342 350 return findBaseTopicName($myTopic); 343 351 } … … 347 355 my $params = shift; 348 356 my $lang = currentLanguage(); 349 return ( TWiki::Func::extractNameValuePair($params, $lang));357 return (Foswiki::Func::extractNameValuePair($params, $lang)); 350 358 } 351 359 -
trunk/TopicTranslationsPlugin/lib/Foswiki/Plugins/TopicTranslationsPlugin/build.pl
r1065 r4517 9 9 } 10 10 11 use TWiki::Contrib::Build;11 use Foswiki::Contrib::Build; 12 12 13 13 # Create the build object 14 $build = new TWiki::Contrib::Build( 'TopicTranslationsPlugin' );14 $build = new Foswiki::Contrib::Build( 'TopicTranslationsPlugin' ); 15 15 16 16 # Build the target on the command line, or the default target
Note: See TracChangeset
for help on using the changeset viewer.
