How to change base config dynamic? |
How to change base config dynamic?
In Ci3 If you would like to dynamically set a config item or change an existing one, you can do so using: Code: $this->config->set_item('item_name', 'item_value'); Can I dynamically set the controller to Ci4? Example: $defaultLocale, $supportedLocales, $appTimezone (01-09-2019, 09:32 AM)titounnes Wrote: You can try like this. Or a bug, or I do not understand. Lang added app/congig/App.php Code: public $defaultLocale = 'en'; in controller Code: public function index() in views Code: <?= lang('app.firstLine'); ?> With language file takes from the English.
@ramstudio what's your Browser language set to? The negotiation feature works with the browser to detect the language it should use. It's possible that if you have your browser language set to English than it's negotiating the language and setting it to English, even though the sites default is Russian.
What happens if you either turn off negotiateLocale or take English out of the supportedLocales? (01-11-2019, 08:40 AM)kilishan Wrote: @ramstudio what's your Browser language set to? The negotiation feature works with the browser to detect the language it should use. It's possible that if you have your browser language set to English than it's negotiating the language and setting it to English, even though the sites default is Russian. In Config\App.php Code: public $defaultLocale = 'en'; In Controller\Home.php Code: <?php namespace App\Controllers; In Views\welcome.php Code: <?php The output comes from the English language file. Although the controller Set Russian. $negotiateLocale When you change the controller true or false - not working. $negotiateLocale When you change the config/App.php true or false - working.
Looks like a workflow we didn't take into account then. Will have to look into that. Thanks.
I've created an issue for this over at GitHub for us to investigate.
However, I did have one thought. I believe the language negotiation is happening prior to the controller being ran, which means it's too late at that point. If you change that dynamically in a pre system event listener it might work there. I don't have any time to investigate until later but that might get you up and running.
Doh! I got to thinking about this after the previous posts and remembered that the request object has a setLocale() method. So, from your controllers you should be able to simply do:
Code: $this->request->setLocale('ru'); As long as that is set prior to using a language string I believe it should do what you're looking for. (01-11-2019, 11:40 PM)kilishan Wrote: Doh! I got to thinking about this after the previous posts and remembered that the request object has a setLocale() method. So, from your controllers you should be able to simply do: This is even better than I could have imagined. Thank you so much. |
Welcome Guest, Not a member yet? Register Sign In |