I am currently learning to localize my L5 installation, thus, I am interested in this topic. As far as I can tell, the localization still works out of the box with L5. You have a default language set in the config and a fallback language. And according to my experience, this is fetching the respective language resource from the respective folders.
http://laravel.com/docs/5.0/localization
But L5 (and I guess L4 too) does not have a native multilanguage feature. You will probably have to install a package for that. Something like
https://github.com/mcamara/laravel-localization
Question: Where exactly did you try to use the 'trans' method? In a view file? I can only confirm that it works properly in view files so far...
Localization itself works out of the box in L4 and L5, but there is one difference:
In L4 you could add whatever folder structure you like to your app/lang/{locale}/
directory, you could easily access those files (even in subdirs) by Lang::get('directory_1.directory_2.[...].directory_n.key')
in your views.
In L5 only those files in the directory resources/lang/{locale}/
(without subdirs) are loaded.
A value in resources/lang/en/foo/bar.php
cannot be called in views by Lang::get('foo.bar.key')
(which is by the way the same like trans('foo.bar.key')
).
Having multiple lang files, I find it reasonable to organize those in several subfolders.
You may be right. I think I tried subfolders too at the beginning, but decided then to use underscores to "categorize" my language files, e.g. foo_bar.php. I will check asap. I will then also try other delimiters like '/'.
For your example you need to specify the path as:
trans('foo/bar.key');
For those who are facing the same problem with sub directories in Laravel 5. Its working, but you have to add a slash to the directories instead of a point.
e.g
{{ trans('foo/bar/foo.key') }}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community