Is there possibly a better way to store large amounts of text for localization in laravel? It would be easy if my entire page was just pure text, but several of my pages have complex layouts and I need to add multiple strings to wrap the text around content such as images/links/media.
This is a pain if I ever need to italicize/bold or do any sort of HTML for the text as well as I need to break them into sections to be able to do that.
An example of what I'm using:
return array(
'exchange_rate' => array(
'title' => 'Exchange Rate',
'p1' => 'Disclaimer',
'p2' => 'Currency rate displayed is subject to change.',
'p3' => 'View All Rates to Date'
),
The first array is the page, the second is the content of the page. I often have to go multiple arrays deeper for more complex layouts such as:
return array(
'exchange_rate' => array(
'title' => 'Exchange Rate',
'p1' => 'Disclaimer',
'p2' => 'Currency rate displayed is subject to change.',
'p3' => 'View All Rates to Date',
'table1' => array(
'title' => 'Currency Table',
'row1' => array(
'l1' => 'Current Rate'
),
'row2' => array('etc')
)
);
Am I doing this right? Is there a better way to format my language files so I can work around the layouts in my views? I'm just curious how large websites manage localization.
Any help is greatly appreciated, thanks!!
EDIT: I'm also aware that you can add placeholders inside your localization arrays such as:
'title' => ':title'
But adding place-holders for all of my links, images, and media on one page could get messy. Laravel also doesn't support HTML inside the language arrays so I can't just plop in content inside the language files. - Yes it does
As it stands now there seems to be two different ways to go here.
EDIT (Feb 10th 2015):
After lots searching, I've created a package as well that suits my needs. It completely removes the need for any text arrays in laravel. It will automatically add text to the database and translate it to your set locale. Plus, you don't need to manage and decipher dot-notated translation paths.
https://github.com/stevebauman/translation
You will learn how to work with translation files, perform pluralization, create a language switcher, and more with laravel localization and multi-language examples. Localization is the second phase of the Laravel internationalization (i18n) process. In Laravel i18n, an application is designed to fit various languages and cultures.
Creating a multi-language website requires two steps. Firstly, you need to detect user local language setting and change it bu user choice. Secondly, you need to translate messages and strings into user local language, in which we use Laravel localization.
Secondly, you need to translate messages and strings into user local language, in which we use Laravel localization. In order to detect user language setting, we need to create a language middleware. this middleware checks for locale setting in the user session.
All you need to do is replace the “Welcome to our website” text with the following code: { { __ ('Welcome to our website') }}. This will instruct Laravel to display “Welcome to our website” by default and look for translations of this string if a non-English language is set (we’ll get to this later on).
I have written a package to generate lang files for you. Write your templates, controllers, ... without boring with translations. When you have finished to code, just execute php artisan localisation:missing
and it will generate all needed files in your lang/*/
directories.
It will synchronize translations :
The package is available here : https://github.com/potsky/laravel-localization-helpers
In daily usage, it is the same workflow as po files. Let me know if your life is easier now with translations in Laravel awesome framework !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With