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.
ucfirst
orlcfirst
where needed, or as complex as it needs to be, because again there is no general solution. – Neutrans
function also in Laravel 4, I use it to and it work like a charm with something liketrans("menu.labels.users")
I will get the exact value that I use , andtrans("menu.labels")
will return all the values inside the labels array – Calvados