Solonik77 / digitalus-cms

Automatically exported from code.google.com/p/digitalus-cms
0 stars 0 forks source link

Multilanguage through csv files is broken or not supported and multilanguage through csv files for modules is broken or not supported #84

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Add a line in the csv file
2. change language
3. line isn't translated in the frontend using getTranslation() helper

Multilanguage for Modules
1. add in modules/module/data/language/english.csv a line
2. change the language
3. line isn't translated in the frontend using getTranslation() helper

What is the expected output? What do you see instead?
the expected output is that the line is translated according the
translation in the csv file

What version of the product are you using? On what operating system?
Digitalus 1.5.1 on a Ubuntu server

Please provide any additional information below.

The problem is that only the translations for the default language
configured in the config.xml file are loaded.
So if you ask the translate adapter for a translation other than the
default language ($adapter->isAvailable($currentLanguage)) it returns false.

The problem of multilanguage for modules is almost the same. Even here the
default language file will never be loaded.

I've created a patch for this problem ( see the code below or the attached
file) I've created a new internal function to load the language files for
every module and a foreach for loading all other site wide languages.

Please let me know if this is the right way to fix this problem. It works
for me ;)

Thnx in advance,

Dennis-Jan

public function initLocale()
    {
        //set defualt locale
        setlocale(LC_ALL, $this->_config->language->defaultLocale);
        $locale = new Zend_Locale($this->_config->language->defaultLocale);

        //translations
        $languageFiles = $this->_config->language->translations->toArray();
        $language =  $this->_config->language->defaultLocale;

        $adapter = new Zend_Translate('csv',$this->_config->language->path
. '/' . $languageFiles[$language] . '.csv',$language);

        $this->loadLanguagesForModules($adapter, $languageFiles);        

        unset($languageFiles[$language]);

        if (is_array($languageFiles) && count($languageFiles) > 0) {
            foreach ($languageFiles as $language => $languageFile) {
                $file = $this->_config->language->path . '/' . $languageFile .
'.csv'; 
                    if (file_exists($file))  {            
                        $adapter->getAdapter()->addTranslation($file,
$language);  
                    } 
            }
        }

        Zend_Registry::set('Zend_Translate', $adapter);
    }

    /**
     * This function adds the translations files for every modules to the
Zend Translate Adapter.
     * Every language for the languages specified in the config file are
loaded and available.
     *
     * @param Zend_Translate $adapter
     * @param Array $languageFileNames
     */
    private function loadLanguagesForModules($adapter, $languageFileNames) {
        $extensions = DSF_Filesystem_Dir::getDirectories($this->_root . 
'/application/modules');

        if (is_array($extensions)) {            
            foreach ($extensions as $extension) {
                foreach ($languageFileNames as $language => $languageFileName) {
                    $file = $this->_root .  '/application/modules/' . $extension
. '/data/language/' . $languageFileNames[$language] . '.csv'; 
                    if (file_exists($file))  {            
                        $adapter->getAdapter()->addTranslation($file,
$language);  
                    } 
                }  
            }        
        }
    }

Original issue reported on code.google.com by dennisja...@gtempaccount.com on 31 Mar 2009 at 3:08

Attachments:

GoogleCodeExporter commented 8 years ago
Hello Dennis-Jan,

first of all, the csv files are for the translation of the BACKend, not the 
frontend.

Secondly, have You checked the most current files from the SVN?
http://code.google.com/p/digitalus-cms/source/browse/trunk/application/Initializ
er.php

The language files for modules are loaded in the initControllers() method. We 
could
discuss if it should be pushed into an own method; but that's it for now.

Cheers,
LowTower.

Original comment by lowtower1974@gmail.com on 31 Mar 2009 at 5:23

GoogleCodeExporter commented 8 years ago
This issue is a duplicate and is closed as Dennis-Jan doesn't reply to my mail!

Cheers,
LowTower.

Original comment by lowtower1974@gmail.com on 29 Apr 2009 at 8:14

GoogleCodeExporter commented 8 years ago
Hello LowTower,

I do need a way to translate sentences in a template. So I will use my solution 
to
achieve such translation behavior for the frontend. Or do you have a proposal to
achieve this behavior?

In my opinion loading the languages isn't the responsibility of the 
initControllers
method but more the responsibility of the initLocale method.

So my problem isn't solved with your proposal :)

Cheers Dennis-Jan

Original comment by dennisja...@gtempaccount.com on 30 Apr 2009 at 9:18