Jump to content

Some modules transaltion incompatibility between 1.4 and 1.2/1.3


olea

Recommended Posts

Some translations done in modules are not compatible between 1.2/1.3 and 1.4, cf report 8167

Problem:
When translating a module, the translation tools of Prestashop generates fiels .php in each module directory (lang being the iso code of the language).

In these files, each string to translate is identified by a key build with :
-- directory name of the module
-- name of the file calling the translation ($this->l())
-- string to translate.

Traduction tools of 1.4 (SVN5505) uses directory name and file name in lowercase, whereas the 1.3 uses upper and lower cases as found in the file system.

For modules translated in 1.3, normally no issue : prestashop 1.4 will convert uppercase keys of the 1.3 into lower cases.

But there is an issue for modules translated on 1.4 and installed on 1.3
If the directory name of the module or name of files calling translaing contains uppercases, the corresponding translations are lost on 1.3 : firstly they are not seen, secundly they are removed from translation file when any module is translated.

Solution :
A compatibility conversion have to be doen when module is installed on version previuos to 1.4.

This is done with the following method that have to be called at the beginning of the install() method of the module.

   static function revert_translation_to13 ()
   {
       if (version_compare(_PS_VERSION_, '1.4') >= 0)
           return ;

       $lang_files = array();
       foreach (Language::getLanguages(false) as $lang) {
           $filename = dirname(__FILE__).'/'.$lang['iso_code'].'.php';
           if (file_exists ($filename))
               $lang_files[$lang['iso_code']] = file_get_contents ($filename);
       }

       $module = basename(dirname(__FILE__));
       $files_list = array();
       $content = @scandir(_PS_MODULE_DIR_.$module);
       foreach ($content as $cont) {
           if ($cont{0} != '.' AND $cont{0} != '..' AND $cont != 'img' AND $cont != 'mails' AND $cont != 'js' AND is_dir(_PS_MODULE_DIR_.$module.'/'.$cont)) {
               if ($files = @scandir(_PS_MODULE_DIR_.$module.'/'.$cont))
                   foreach ($files as $f) 
                       if (strpos($f, '.php') !== false AND is_file (_PS_MODULE_DIR_.$module.'/'.$cont.'/'.$f))
                           $files_list[] = str_replace('.php', '', $f);
           } elseif (strpos($cont, '.php') !== false AND is_file(_PS_MODULE_DIR_.$module.'/'.$cont))
               $files_list[] =  str_replace('.php', '', $cont);
       }

       $module_lowered = strtolower($module);
       foreach ($files_list as $f) 
           foreach($lang_files as $iso=>&$content) 
               $content = str_replace ('<{'.$module_lowered.'}prestashop>'.strtolower($f).'_', '<{'.$module.'}prestashop>'.$f.'_', $lang_files[$iso]);

       foreach ($lang_files as $lang=>$langfile_content)
           file_put_contents(dirname(__FILE__).'/'.$lang.'.php', $langfile_content);
   }


   function install()
   {            
       self::revert_translation_to13();
       /*
        ** installation du module
        */
   }

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...