This is a question about methodology and suggested practices. I know it is not strictly attached to the framework and not even PHP, and the answer might be "its up to you". But my concern is about best practices and methodology, as there usually exists a best approach for a certain context.
I would like to know which are the best practices for key naming for the trans()
function of Laravel 5.1 ?
Considering that built-in Laravel translations are stored into an array, my concern is which hirearchy allows me to achieve the following goals:
consistency: So I minimize the possibility of using different words for the same meaning, or creating many different keys that end up having the same translation (like common words).
reusability: So I minimize the overall translation files size and translate as less as possible, and preserve flexibility.
readability: So translators can identify the purpose of the key even under lack of the translation value.
organization: So developer can easily remember the full key path and minimize checking the transalation files each time.
To give an example, lets say I want to name a successful alert for User model update, for a management profile. Possible approaches are:
trans('manager.user.update.alert.sucess')
trans('alerts.success.manager.user.update')
trans('manager.user.alert.update.success')
trans('alert.the_user_was_updated_successfully')
Update
By Nov-2016, it looks like Laravel 5.4 is introducing a JSON based translation mechanism that might simplify translation files. Still, caring for smart file structure and well organized texts are a plus.