Hello, I've tried to autoload some lang files that I, will always use across the system I'm implementing, And I want to have i18n, so what I do is autoloading lang files for buttons for example (add, send, save, ok, cancel) and loading specific lang files before() the controller action is called
Loading custom lang files is pretty simple, that's not a problem
Lang::load('file', null, 'lang');
But changing the language of autoloaded files is a pain, using Config::set('language', 'somethinginsession'); in before() method won't load my "buttons text" in the language user needs, but the default one.
Another thing I found is that using 'group.key' in Form::label('group.key') will load text from language files, but for submit, won't load from file if I use Form::submit('value', 'group.key')
Thanks in advance
Autoloading happens during Fuel's init phase, so way before any controller is loaded.
The preferred method is to use a class for it. Create a static _init() method in the class which is called upon loading, and in it load your language code from the session and use Config::set() to update the default. Then set this class as "always_load", which will happen before any language files loaded.
Alternatively, you can update the config directly from the session:
'language' => \Session::get('language', 'en')),
As to the Form class: labels will be auto translated. However, Form::submit() doesn't accept a value and a label, it accepts a fieldname and a value. Values are never auto translated.
Thank you so much for your answer yeah, I though values for submit should be treated like labels as it's the displayed text, but I can live with that
I found that lang keys won't be filtered with output filters when translated, the default value for this is 'output_filter' => array('Security::htmlentities') in my case
output filtering is only relevant for variables you pass on to your views, either through set() or by assigning them to a view property. There is no filtering run on the output itself.