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.
- Continue breaking them into small sections to format text differently.
- Paste the page text into one 'content' array per page, use Waavi to transfer them to the database, and then format them correctly using a WYSIWYG editor on the website itself to format the database entry. (Though this has issues as well because then you can't use blade templating as Lang::get() returns only safe text)
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.