Given that I want to display several keys in english and french and that I have two languages files :
/lang/fr/file.php
containing several 'key' => 'key-in-fr'
/lang/en/file.php
containing several 'key' => 'key-in-en'
How can I display the keys in both languages within the same view ?
I tried :
Lang::load('file','lang-en','en'); // This load returns the array of translations
echo Lang::get('lang-en.key'); // displays correctly 'key-in-en'
Lang::load('file','lang-fr','fr'); // This load returns false
echo Lang::get('lang-fr.key)'; // Fails to display 'key-in-fr'
Thanks
I have set up an app showing the problem I'm facing with language management.
The basic idea behind this example is that I have to be able to manage two language environments :
- The application language (defined by the user).
- The displayed resource language (defined by content).
When I'm in my application, let's say I'm an english user, I expect the application to talk to me in english.
But within that application, I need to be able to to display resources that are in other languages.
The demo show my attempt to achieve that but it doesn't work... should I change something or should the Fuel language management evolve a little bit further ?
You can download the demo at : https://github.com/dimitridamasceno/fuel-lang/tree/1.4/develop
Thanks for reading,
Dimitri
The language settings at the moment are meant to be, as you call it, for application language. Which means it's set once (based on accept-language, parameter, cookie setting, user preference, etc), and used throughout the entire application.
Languages are global, there is no per-request context for languages. As 1.4/develop now doesn't overwrite loaded files in different languages anymore, it would be possible to push the current language on the stack when you start an HMVC request, and pop it again when the request returns.
This would allow you to set a different language in your HMVC request, load files if needed, without having an impact on the language set in the parent request.
Would that help you out? If so, please create a feature request for it on http://github.com/fuel/issues so it can be picked up by one of the devs.
Currently you can't. Language files are loaded into in internal unified structure that has no concept of language.
If you think this is functionality more people would want, create a feature request at http://github.com/fuel/core/issues.
You can work around it by setting language A, load the language file, fetch the data, set language B, load the language file again (make sure you force a reload), and fetch the data.
Thank you for your answer.
I will try your work around.
Launching a feature request sounds a good idea. However, I don't know how much interest would such feature be for others.
I'll keep that opportunity in mind.