Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yii::t() should fall back to substr(Yii::app()->language, 0, 2) #2057

Closed
fiesh opened this issue Jan 30, 2013 · 8 comments
Closed

Yii::t() should fall back to substr(Yii::app()->language, 0, 2) #2057

fiesh opened this issue Jan 30, 2013 · 8 comments
Assignees
Milestone

Comments

@fiesh
Copy link

fiesh commented Jan 30, 2013

When you have your target language set to say fr_fr, Yii::t() should first check if there is a translation in fr_fr, and then, if not, fall back to just 'fr'. For example, setting your language to fr_fr will not even produce Yii's native translations!

Is there any negative side effect of this? I cannot think of one.

@njasm
Copy link
Contributor

njasm commented Jan 31, 2013

Never thought about this, but you might have a valid point here.

@cebe
Copy link
Member

cebe commented Jan 31, 2013

Came across this issue too, just yesterday. Not easy to solve in current code.

@ghost ghost assigned cebe Jan 31, 2013
@qiangxue
Copy link
Member

We don't support language fallback mainly for performance concerns.

Language fallback can be done at different places. For example, if your application only supports 'fr', then whenever your get 'fr_fr' from user, you can change it to 'fr', thus avoiding the issue you describe here.

If your application supports both 'fr' and 'fr_fr', but your message translations don't, you can use some external tools to build up your messages so that both languages are supported.

@njasm
Copy link
Contributor

njasm commented Jan 31, 2013

Since Qiang was very clear regarding translation fallback inside yii i didn't conduct further testing ... but I got an initial version that's working with php files translations (no db source translations tested).

if Performance is not a 'BIG' concern to you/your project, take in consideration this new implementation of CMessageSource::translateMessage()

https://gist.github.com/91209e1278e14051f555

if you really want fallback translation you could also use onBeforeAction() to substring language to 2 char in size (if for some reason language are 5 char length and you don't have a way to control that), just don't forget to rename all your translation language folders to two chars in length too (if you using PHP files translations, i've never used db source translations).

Kisses and Hugs.

@fiesh
Copy link
Author

fiesh commented Jan 31, 2013

I disagree with Qiang's statement that you can just change the language to the short 2 character version. You might still want the formatting of currencies and numbers to depend on the longer locale (en_gb and en_us are vastly different, for example). Also, if there was an option $fallback for the CMessageSource, it wouldn't imply any performance penalty. As for implementing it, one can just alter translateMessage() in CPhpMessageSource, that's what I did, and it works fine. (Oh, njasm also did that, the implementation is very similar to mine, thanks.)

So I remain this would be a good feature ;)

All the best!

@qiangxue
Copy link
Member

I'm not saying using 'en' to represent both 'en_gb' and 'en_us' (we know they're different).

What I was suggesting is that the fallback can be done earlier than on-the-fly because the fallback mechanism is not trivial (could go as many as 4 layers, c.f. http://userguide.icu-project.org/locale#TOC-Fallback)

@mdomba
Copy link
Member

mdomba commented Jan 31, 2013

This is similar to #698

@fiesh
Copy link
Author

fiesh commented Jan 31, 2013

Qiang, sorry, then I misunderstood what you said. I wasn't aware of the fact there's a standardised fall back routine. I agree that this should be implemented then. But I can't tell how big the performance impact would be, it doesn't seem noticeable for me, but then it might vary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants