-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Internationalization docs : setting the application language at runtime - is not clear #6568
Comments
|
I don't think there's anything missing in the guide in this regard. It is as simple as it's described. Just one line of the code. |
So I have links in my main.php layout file that point to SiteController/language action like this:
This is my language action:
When user press language link, all I get is white screen. Docs says that I should set language before any output, but how I am supposed to do that ? I dont get this... |
You're doing it almost right except:
|
I'll cover it in cookbook but a bit later. |
Thanks a lot for your help, I made it work, but I am not sure if this is the best way to do it. Here is what I did:
Inside my config file I am using on beforeRequest event to set language like this:
Is this good way to do it ? |
I'd use cookies instead of session not to loose setting when coming back after period of inactivity. The rest seems good. One thing is that if you're providing content using different language it worth having language in URL instead of just storing it in a cookie. |
How is that supposed to work ? I mean having language in URL o.O. I store it there somehow ? |
I mean having separate URLs for separate languages:
or
In this case you don't have to store. Instead you're just redirecting to another language URL. There are many ways of implementing it. That's why there's no concrete example in the guide. |
Thanks, but I have not idea how to implement that. |
there is an extension for this: https://github.com/codemix/yii2-localeurls |
I did exactly what installation says for that extension, and when I run my application I just get white screen... |
@offline-online check your error logs |
runtime debug and logs are empty |
Ok, it was comma issue, I can run application now. BUT, it will always run with default en_US locale. How do I have to modify my code to allow users to chose language ? code in main.php layout:
Language action in SiteController :
Setting language in cookies also do not help. |
I got it. Thanks all for helping. Thanks cebe A LOT, it is good extension. |
I am new to Yii and new to Internationalization. I would like make my site to support many languages, and I need to allow users to chose their language. So I need to set the application language at runtime. This is all that we get in guide:
You may set the application language at runtime to set it to a language the user has chosen. This has to be done at a point before any output is generated so that it affects all the output correctly. Therefor just change the application property to the desired value:
\Yii::$app->language = 'zh-CN';
\Yii::$app->language = 'zh-CN';
? And how we are supposed to take user requested language and act based on that ?Can you please provide real world example of this process ?
The text was updated successfully, but these errors were encountered: