I faced this problem several times while building websites. I will explain the using PHP and Laravel as an example but this problem is a common amoung multiple platforms. This was already addressed in a few questions (post1, post2,post3, post4 and some others) but the posts didn't really get a good answer.
The question is: What is the best way of structuring translated content inside of language files?
I'm currently using Laravel (I'm not mentioning the version because both Laravel 4 and Laravel 5 have similar localisation functionalities, at least similar enough for the purpouses of this topic).
The localisation structures the content accross language files (en, es,de, fr...) inside which there can be multiple .php files that contain a return statement that returns a multi-level dictionary structure.
/lang
/en
messages.php
/es
messages.php
and the files contain something like this:
<?php
return [
'example1' => 'example message for value exaple-key',
'example2' => [
'sub-example' => 'example message for example1.sub.example',
],
];
and calling of this is done by doing something like this:
//Laravel 5
trans('messages.example1'); //outputs 'example message for value exaple-key'
trans('messages.example2.sub-example'); //outputs 'example message for example1.sub.example'
//Laravel 4
Lang::get('messages.example1'); //outputs 'example message for value exaple-key'
Lang::get('messages.example2.sub-example'); //outputs 'example message for example1.sub.example'
A few methods of grouping come to mind:
by website content
example: homepage.php, page1.php, page2.php...
by logical domain:
example: auth.php, validation.php, pagination.php...
by html:
example: buttons.php, popup_messages.php, form_data.php...
by straight traslation:
example: simple_words.php, phrases.php...
and than contain content like 'password-to-short' => 'your password is to long'
Some hybrid/combination of the ones mentioned before
All of these have some obvious benefits and drawbacks and I won't try to go int that but the 5th option is most likely the best solution but there's still the problem of where to draw the line to get minimal duplication of phrases and content.
Annother problem is how to solve the problem of uppercase first characters in some cases and lowercase in other cases as well as punctuation characters at the ends.
I did reaserch regarding this problem but there are no definitive guidelines and/or good examples available to learn from.
All opinions are welcome.
If you'd like to translate an entire website at once, you can use Google Translate. Putting a URL in Google Translate to translate the entire site. Select the target language from above the text box on the right. Once you click on the link, you should see a fully translated version of the website.
Generally, there are three types of translator: compilers. interpreters. assemblers.
I tend to group functionality in my Laravel apps into self-contained ‘components’. For example, I’ve been working on email campaign functionality for an application recently so put the service provider class, models, service classes in a folder at app/Email.
Bearing this in mind, I organise my translations in a similar fashion. So even though on this project we’re not translating strings, if we were I would create a resources/assets/lang/en/email.php file, and put translated strings for the email component in there.
So in another project, my directory structure might look like this:
Hope this helps.
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