Task #3079

Change localisation system : use gettext

Added by moyo over 2 years ago. Updated almost 2 years ago.

Status:Closed Start date:08/25/2011
Priority:Normal Due date:
Assignee:moyo % Done:

100%

Category:Common
Target version:0.84

Description

Problems found :
  • Several translations in english to Update (mettre à jour / actualiser...)
  • Problem with units when Dropdown+units : need to manage it on a string to be RTL compatible. So dropdowns need to be able to give results as a string not echo them.
  • Problem of unit order and pass to string : %1$s premier param %2$s 2eme param.
    • printf('%1$s %2$s', $string, $unit); will be translated in RTL by : '%2$s %1$s'
    • To manage RTL language need to review all concatenate strings :
      • $data[$NAME.$num].$unit; will become sprintf('%1$s%2$s',$data[$NAME.$num],$unit) and will be translated by %2$s%1$s for RTL
    • Better solution : display units in header of list and not in content. Title (unit). Same idea for displaying dropdowns (units in lib) : ex Rafraichissement automatique de la liste des tickets (jour(s)):
using Zend_Translate / think to manage contexts.
Create standard functions :
  • __ get string
  • __s get a addslashes string
  • _e to echo string
  • _n get plural
  • not yet :
    • _nx get plural with context
    • _x get string with a context
    • _ex echo string with a context
  1. Move existing LANG call to new system
    1. Clean concatenation of strings.
      $tab[36]['name']          = $LANG['devices'][4]." ".$LANG['setup'][35];
      devient
      $tab[36]['name']          = __('Processor frequency');
      
    2. Use plural forms to be more simple
            if ($nb>1) {
               return $LANG['Menu'][0];
            }
            return $LANG['help'][25];
      
          devient
          return __p('Computer','Computers',$nb);
      
    3. One line = one string to manage correctly Right to Left Languages
                  echo $LANG['common'][52]." <a href='".$CFG_GLPI["root_doc"]."/front/ocsserver.form.php?id=" 
                       .OcsServer::getByMachineID($ID)."'>".OcsServer::getServerNameByID($ID)."</a>";
      
                  if ($data_version["ocs_agent_version"] != NULL) {
                     echo " , ".$LANG['ocsng'][49]."&nbsp;: ".$data_version["ocs_agent_version"];
                  }
      
      deviendrait
      
      echo printf(__("Server <a href='%s'>%s</a>",
                       $CFG_GLPI["root_doc"]."/front/ocsserver.form.php?id=".OcsServer::getByMachineID($ID), 
                       OcsServer::getServerNameByID($ID));
      
                  if ($data_version["ocs_agent_version"] != NULL) {
                     echo '<br>';
                     printf(__("Agent: %s"),$data_version["ocs_agent_version"]);
                  }
      
      
  2. generate en.po using xgettext : xgettext testZend.php -o po/template.pot -L PHP --from-code=UTF-8 --force-po --omit-header --keyword=__p:1,2 --keyword=__
  3. Upload en.po to translation tool (transifex for example)
  4. Generate complete po files for all translations based on existing LANG files : all strings in po
    1. Manages plural : Computer / Computers : Need 1 plural form + 1 single for simple plural
    2. How to manage contexts ?
    3. Upload generated po to translation tool to keep existing valid translations
  5. extract po files from translation tool : need to create a script extraction + compiling in mo + commiting

Exemple of code :

require "Zend/Translate.php";

      $translate = new Zend_Translate (
          array(
              'adapter' => 'gettext',
              'content' => './po/fr.mo',
              'locale'  => 'fr'
          )
      );

      $translate->addTranslation(

         array(
            'content' => './poplugin/fr.mo',
            'locale'  => 'fr'
         )

      );

$translate->setLocale('fr');

function __($str){
   global $translate;

   return  $translate->_($str);

}

function __p($sing,$plural,$nb){
   global $translate;

   return  $translate->plural($sing,$plural,$nb);

}

function toto (){

      print __("Test") . "\n";
      print "=======\n";
      print __("Test 2") . "\n";
      print "=======\n";
      print __("Test Plugin") . "\n";

}

toto();

      $translate->addTranslation(

         array(
            'content' => './po/ru.mo',
            'locale'  => 'ru'
         )

      );

   $translate->setLocale('ru');

toto():

Associated revisions

Revision 16289
Added by moyo over 2 years ago

work on gettext see #3079

Revision 16291
Added by moyo over 2 years ago

work on gettext see #3079

Revision 16292
Added by moyo over 2 years ago

work on gettext see #3079 end of buttons module

History

Updated by moyo over 2 years ago

  • Assignee set to moyo

Updated by moyo over 2 years ago

  • % Done changed from 0 to 30

Updated by moyo over 2 years ago

  • % Done changed from 30 to 80

Updated by moyo almost 2 years ago

  • % Done changed from 80 to 100

Updated by moyo almost 2 years ago

  • Status changed from New to Closed

Also available in: Atom PDF