Kris
Kris

Reputation: 912

Zend Translate custom language

Depending on the user role, I need to show different texts in my Zend project.

However, the language "en_new" always reverts to just "en".

I'm using the locale_directory scan system to automatically detect languages.

Upvotes: 1

Views: 857

Answers (2)

enricog
enricog

Reputation: 4273

I am currently evaluating something similar, for some users I want some texts to be differently translated. And I also ran into the problem to not be able to create a custom locale value. Tough what I found out in my tests seems to solve/work around the problem.

See also here: Combining multiple translation sources

What I am doing is to just add a custom translation to my default ones.

$translateDef = new Zend_Translate(
   array(
       'adapter'    => 'gettext',
       'content'    => 'locale/default/',
       'locale' => 'auto',
       'scan'       => Zend_Translate::LOCALE_DIRECTORY
   )
);

$translateCust = new Zend_Translate(
   array(
       'adapter'    => 'gettext',
       'content'    => 'locale/custom/',
       'locale' => 'auto',
       'scan'       => Zend_Translate::LOCALE_DIRECTORY
   )
);

$translateDef->addTranslation(array(
       'content'    => $translateCust
    )
);

And the folder structure looks like this:

locale/
       default/
               de
               en
       custom/
               de
               en

So when doing the addTranslation it seems to overvwrites the existing ones, so for your new users, you could add custom folder with the proper translations. For my tests this worked so far, but haven't evaluated it in depth yet.

Upvotes: 0

bububaba
bububaba

Reputation: 2870

The translate adapter calls Zend_Locale::findLocale() internally in addTranslation() (at least in ZF 1.1x). This in turn checks whether the locale is on a whitelist. Yours is not, obviously. I didn't dig too deep into the code, but it's quite probable that the next step is to revert from en_xxx to just en which is what happens in your case.

See the sources:

  • library/Zend/Translate/Adapter.php - addTranslation method
  • library/Zend/Locale.php - findLocale method

Upvotes: 1

Related Questions