Changeset 4517


Ignore:
Timestamp:
07/21/09 16:08:35 (3 years ago)
Author:
AntonioTerceiro
Message:

Item5692: new release of TopicTranslationsPlugin

  • New %CURRENTLANGUAGESUFFIX% macro.
  • Porting to Foswiki
  • Removed references to TWiki were applicable.
  • updated copyright notice
  • Adding a proper build system
  • Using regular regular expression delimiter in the SCRIPT_ENV test
Location:
trunk/TopicTranslationsPlugin
Files:
6 added
2 deleted
3 moved

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"}% 
    22---+!! !TopicTranslationsPlugin 
    33 
     
    1616Each web that is going to use !TopicTranslationsPlugin must define a variable named 
    1717=%<nop/>TOPICTRANSLATIONS%=, which must contains a comma-delimited list of language 
    18 code. =%<nop/>TOPICTRANSLATIONS%= can be defined TWiki-wide, which means that those 
    19 languages will be used for the entire TWiki installation. It can also be defined 
     18code. =%<nop/>TOPICTRANSLATIONS%= can be defined system-wide, which means that those 
     19languages will be used for the entire site. It can also be defined 
    2020per user. If none of th above is set, the plugin setting for !TopicTranslationsPlugin 
    2121with the same name (=%<nop/>TOPICTRANSLATIONS%=) will be used as a default. 
     
    7070The language detected for the current topic (based on the current topic's name suffix). 
    7171 
     72---+++ =%<nop/>CURRENTLANGUAGESUFFIX%= 
     73 
     74The language suffix of the current topic (empty if the current topic is in the 
     75default language, since the default language has not suffix). This is useful 
     76in 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 
    7282---+++=%<nop/>DEFAULTLANGUAGE%=  
    7383 
     
    109119 
    110120It'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 obsolete 
    112 TWiki:Main/FreeSkin), or even site-specific custom skins. 
     121similar way of making user-editable custom layouts (like the obsolete 
     122[[TWiki:Main/FreeSkin][FreeSkin]]), or even site-specific custom skins. 
    113123 
    114124%RED% __Warnings:__ %ENDCOLOR% 
     
    116126   * This tag is a workaround for sites that want to display user-written 
    117127     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. 
    120129   * 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. 
    124134 
    125135---++ Automatic Redirection 
     
    144154from =no=, =off= and =0=). 
    145155 
    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 
     158this work you'll have to apply the following patch to =TWiki/Func.pm= module 
     159(got from TWiki's Subversion repository):  
    148160 
    149161<verbatim> 
    150 --- /var/lib/twiki/lib/TWiki/Func.pm    2005-07-02 13:33:46.893777128 -0300 
     162--- /var/lib/twiki/lib/Foswiki/Func.pm    2005-07-02 13:33:46.893777128 -0300 
    151163+++ Func.pm     2005-07-02 13:37:22.187047576 -0300 
    152164@@ -407,8 +407,9 @@ 
     
    163175 # ========================= 
    164176</verbatim> 
     177</blockquote> 
    165178 
    166179---++ Examples 
     
    193206---++ Plugin Installation Instructions 
    194207 
    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.  
    196209 
    197210   * Download the ZIP file from the Plugin web (see below) 
     
    201214     | ==data/System/%TOPIC%.txt,v== | Plugin topic repository | 
    202215     | ==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. 
    204217   * Test if the installation was successful: 
    205218      * see the examples [[#Examples][above]] 
     
    207220---++ Plugin Info 
    208221 
    209 |  Plugin Author: | TWiki:Main.AntonioTerceiro | 
    210 |  Copyright: | &copy; 2006, TWiki:Main.AntonioTerceiro | 
     222|  Plugin Author: | Foswiki:Main.AntonioTerceiro | 
     223|  Copyright: | Copyright &copy; 2005-2009, Foswiki:Main.AntonioTerceiro | 
    211224|  License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) | 
    212225|  Plugin Version: | 03 Jul 2005 (V1.003) | 
     
    220233|  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=).  | 
    221234|  19 Jun 2005: | Initial version: =1.001= | 
    222 TWiki Dependency: | $TWiki::Plugins::VERSION 1.024 | 
     235Foswiki Dependency: | $Foswiki::Plugins::VERSION 1.024 | 
    223236|  CPAN Dependencies: | =I18N::AcceptLanguage= | 
    224237|  Other Dependencies: | none | 
     
    229242__Related Topics:__ %SYSTEMWEB%.DefaultPreferences, %USERSWEB%.SitePreferences, [[%SYSTEMWEB%.Plugins][Plugins]] 
    230243 
    231 -- TWiki:Main.AntonioTerceiro - 03 Jul 2005 
    232  
     244-- Foswiki:Main.AntonioTerceiro - 21 Jul 2009 
     245 
  • trunk/TopicTranslationsPlugin/lib/Foswiki/Plugins/TopicTranslationsPlugin.pm

    r1340 r4517  
    11# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/ 
    22# 
    3 # Copyright (C) 2005 Antonio S. de A. Terceiro, asaterceiro@inf.ufrgs.br 
     3# Copyright (C) 2005-2009 Antonio Terceiro, terceiro@softwarelivre.org 
    44# 
    55# This program is free software; you can redistribute it and/or 
     
    1515 
    1616# ========================= 
    17 package TWiki::Plugins::TopicTranslationsPlugin; 
     17package Foswiki::Plugins::TopicTranslationsPlugin; 
    1818 
    1919# ========================= 
     
    3030use I18N::AcceptLanguage; 
    3131 
    32 # This should always be $Rev$ so that TWiki can determine the checked-in 
     32# This should always be $Rev$ so that Foswiki can determine the checked-in 
    3333# status of the plugin. It is used by the build automation tools, so 
    3434# you should leave it alone. 
     
    4747 
    4848    # 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" ); 
    5151        return 0; 
    5252    } 
    5353 
    5454    # Get plugin debug flag 
    55     $debug = TWiki::Func::getPluginPreferencesFlag( "DEBUG" ); 
     55    $debug = Foswiki::Func::getPluginPreferencesFlag( "DEBUG" ); 
    5656 
    5757    # those should be preferably set in a per web basis. Defaults to the 
    5858    # 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"; 
    6060    @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";     
    6363 
    6464    # first listed language is the default one: 
     
    7474 
    7575    # 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")); 
    7777    checkRedirection() if $mustRedirect; 
    7878 
    7979    # 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; 
    8181    return 1; 
    8282} 
     
    8686### my ( $text, $topic, $web ) = @_;   # do not uncomment, use $_[0], $_[1]... instead 
    8787 
    88     TWiki::Func::writeDebug( "- ${pluginName}::beforeCommonTagsHandler( $_[2].$_[1] )" ) if $debug; 
     88    Foswiki::Func::writeDebug( "- ${pluginName}::beforeCommonTagsHandler( $_[2].$_[1] )" ) if $debug; 
    8989 
    9090    # handle all INCLUDETRANSLATION tags: 
     
    9696### my ( $text, $topic, $web ) = @_;   # do not uncomment, use $_[0], $_[1]... instead 
    9797 
    98     TWiki::Func::writeDebug( "- ${pluginName}::commonTagsHandler( $_[2].$_[1] )" ) if $debug; 
     98    Foswiki::Func::writeDebug( "- ${pluginName}::commonTagsHandler( $_[2].$_[1] )" ) if $debug; 
    9999 
    100100    # handle our common tags: 
    101101    $_[0] =~ s/%TRANSLATIONS({(.*?)})?%/&handleTranslations($2)/ge; 
    102102    $_[0] =~ s/%CURRENTLANGUAGE%/&currentLanguage/ge; 
     103    $_[0] =~ s/%CURRENTLANGUAGESUFFIX%/&currentLanguageSuffix/ge; 
    103104    $_[0] =~ s/%DEFAULTLANGUAGE%/$defaultLanguage/ge; 
    104105    $_[0] =~ s/%BASETRANSLATION({(.*?)})?%/&handleBaseTranslation($2)/ge; 
     
    106107} 
    107108 
    108 # transform a language code into a suitable suffix for TWiki topics, 
    109 # by capitalizing the 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. 
    110111# Examples: 
    111112#   pt-br -> Ptbr     EN -> En 
     
    146147} 
    147148 
     149# returns the current language suffix, or '' (empty string) if the current 
     150# language is the default one 
     151sub currentLanguageSuffix { 
     152  my $lang = currentLanguage(); 
     153  return ($lang eq $defaultLanguage) ? '' : normalizeLanguageName($lang); 
     154} 
     155 
    148156# list the translations of the current topic (or to that one passed as an 
    149157# argument). Depending on the arguments to the %TRANSLATIONS% tag, many options 
     
    157165 
    158166    # 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; 
    161169     
    162170    # other stuff: 
    163     my $userSeparator = TWiki::Func::extractNameValuePair($params, "separator") || " "; 
     171    my $userSeparator = Foswiki::Func::extractNameValuePair($params, "separator") || " "; 
    164172 
    165173    #  
    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; 
    167175    my $theWeb; 
    168176    if ($theTopic =~ m/^([^.]+)\.([^.]+)/) { 
     
    176184 
    177185    # 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"; 
    179187    my @whichTranslations; 
    180188    if ($which eq "available") { 
     
    202210 
    203211    # 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); 
    205213 
    206214    # substitute the variables: 
     
    220228    my $theLang = currentLanguage(); 
    221229     
    222     my $theTopic = TWiki::Func::extractNameValuePair($params); 
     230    my $theTopic = Foswiki::Func::extractNameValuePair($params); 
    223231    my $theWeb; 
    224232    if ($theTopic =~ m/^([^.]+)\.([^.]+)/) { 
     
    236244 
    237245    # undef is ok, meaning current revision: 
    238     my $theRev = TWiki::Func::extractNameValuePair($params, "rev"); 
     246    my $theRev = Foswiki::Func::extractNameValuePair($params, "rev"); 
    239247 
    240248    my $args = "\"$theWeb.$theTopic\""; 
     
    268276    my $script = $ENV{SCRIPT_NAME} || '/view';  
    269277 
    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(); 
    272280     
    273281        # several checks 
    274282        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'); 
    277285        my $origin = $query->referer() || ''; 
    278286         
     
    289297              # actually do the redirect: 
    290298              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); 
    293301            } 
    294302        } 
     
    326334         
    327335        # is that translation available? 
    328         $exists = TWiki::Func::topicExists($web, $theTopic . $norm); 
     336        $exists = Foswiki::Func::topicExists($web, $theTopic . $norm); 
    329337 
    330338        # what kind (available or not) are we looking for? 
     
    339347sub handleBaseTranslation { 
    340348    my $params = shift; 
    341     my $myTopic = TWiki::Func::extractNameValuePair($params, "topic") || $topic; 
     349    my $myTopic = Foswiki::Func::extractNameValuePair($params, "topic") || $topic; 
    342350    return findBaseTopicName($myTopic); 
    343351} 
     
    347355  my $params = shift; 
    348356  my $lang = currentLanguage(); 
    349   return (TWiki::Func::extractNameValuePair($params, $lang)); 
     357  return (Foswiki::Func::extractNameValuePair($params, $lang)); 
    350358} 
    351359 
  • trunk/TopicTranslationsPlugin/lib/Foswiki/Plugins/TopicTranslationsPlugin/build.pl

    r1065 r4517  
    99} 
    1010 
    11 use TWiki::Contrib::Build; 
     11use Foswiki::Contrib::Build; 
    1212 
    1313# Create the build object 
    14 $build = new TWiki::Contrib::Build( 'TopicTranslationsPlugin' ); 
     14$build = new Foswiki::Contrib::Build( 'TopicTranslationsPlugin' ); 
    1515 
    1616# Build the target on the command line, or the default target 
Note: See TracChangeset for help on using the changeset viewer.