- Timestamp:
- 07/21/09 16:08:35 (3 years ago)
- Location:
- trunk/TopicTranslationsPlugin/lib/Foswiki
- Files:
-
- 2 added
- 1 moved
-
. (added)
-
Plugins (added)
-
Plugins/TopicTranslationsPlugin.pm (moved) (moved from trunk/TopicTranslationsPlugin/lib/TWiki/Plugins/TopicTranslationsPlugin.pm) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.
