Closed xwz closed 8 years ago
is the mapping needed?
as all the "parent" languages are those before the _, can this be extracted from the $language?
Yes, because some files are based on language, others on the territory part of the locale identifier. Some files use both.
On 10/05/2012, at 7:42 PM, Maurizio Dombareply@reply.github.com wrote:
is the mapping needed?
as all the "parent" languages are those before the _, can this be extracted from the $language?
Reply to this email directly or view it on GitHub: https://github.com/yiisoft/yii/issues/698#issuecomment-5621464
It possible can solve incosistencies we have with jQueryUI locale names.
It possible can solve incosistencies we have with jQueryUI locale names.
Can you elaborate?
This problem needs a more generic solution. Basically we need some sort of fallback mechanism while at the same time not sacrificing the performance too much.
@xwz in order to use localized jQueryUI widgets you need to specify locale. The issue is that locale names aren't the same as in Yii itself.
In my case, I solve this using this function in my Controller class:
static public function fallbackLanguage( $language )
{
$newLang = '';
$changeToLanguage = strtolower( (string) $language );
// find out language
if( !in_array( $changeToLanguage, Controller::$languages ) )
{
foreach( Controller::$languages as $lang )
{
if( substr( $changeToLanguage, 0, 2 ) === $lang )
{
$newLang = $lang;
}
}
if( $newLang === '' )
{
// fallback to english
$changeToLanguage = Controller::$defaultLanguage;
}
else
{
$changeToLanguage = $newLang;
}
}
return $changeToLanguage;
}
This function is called in the Controller constructor. In my case, our logged user has a property for their language, so it makes no sense putting my code of the constructor for you here, but may be it's a good starting point
btw, I have a list of "valid" languages in Controller::$languages I support...
static $defaultLanguage = 'en';
static $languages = array(
'af',
//'ar',
'da',
'de',
'en',
'es',
'et',
'fr',
'ga',
//'hi',
'it',
//'jp',
'pt',
//'ru',
'sv',
'tr',
//'zn',
);
static $languageNames = array(
'af' => 'Afrikaans',
//'ar' => 'العربية',
'da' => 'Dansk',
'de' => 'Deutsch',
'en' => 'English',
'es' => 'Español',
'et' => 'Eesti',
'fr' => 'Français',
'ga' => 'Gaeilge',
//'hi' => 'हिन्दी',
'it' => 'Italiano',
//'jp' => '日本',
'pt' => 'Português',
//'ru' => 'Россию',
'sv' => 'Svenska',
'tr' => 'Türkçe',
//'zh' => '中文',
);
@luislobo I think that's separate issue. This is more about allowing users to use a specific locale and having yii core message still work relatively correct.
Yes, I just contributed with a fallback algorithm, if it helps
For message files I could solve it like this: http://www.yiiframework.com/wiki/504/how-to-provide-a-fallback-or-mapping-for-translation-messages/
Note: Has no effect on locales and views!
@qiangxue Would be nice if Yii2 could address this somehow. Or would aliases even be capable of that?
I think it's not a good idea to do substr, because a lot of js library need "it_IT" format, probably the fallback should be the inverse: when 'it' -> 'it-IT" !
Just on top of my head... if you just want to translate several languages pointing to one only single translation source, you could create symbolic links...
Currently the yii core messages are loaded when the application
language
match exactly the translated message file names.For example, when
language="no"
it will loadmessages/no/yii.php
, however, whenlanguage="nb_NO"
it is unable to loadmessages/no/yii.php
.Proposal:
Register a subclass of CPhpMessageSource for
coreMessages
application component that provides a mapping from more complete locale identifiers (such as"nb_no" => "no"
) to respective translated core messages.