4

As I've started building a project, there will be quite a few entries in the .po translation file. I use Poedit to build these.

My question is, what is the best practice for entries within this file? I was thinking, instead of referencing entries such as:

echo _('This is an entry.');

I was thinking of organizing them like:

echo _('error_pwd');
echo _('error_user_taken');

Which, once ran through the translation file, would output something like:

Password incorrect. Please try again.
Username is already taken. Please try another.

So, all my translations can be organized by type, such as error_, msg_, status_, tip_, etc.

Has anyone seen it done this way, or have any suggestions on a more organized method?

felipsmartins
  • 13,269
  • 4
  • 48
  • 56
MultiDev
  • 10,389
  • 24
  • 81
  • 148
  • Yes - multiple translation files for each type. Other translation libraries support this such as Symfony2, but I don't know about your implementation. – sjagr Apr 28 '15 at 20:33
  • Second is better, maybe you want to change English errors at a later point too, if you use the first and then change English messages, it will cause possible mistakes – Vladimir May 20 '15 at 18:51
  • 1
    I dont understand, i just noticed the date of question which is `asked Apr 28 at 20:29`, and no bounty is set, why are we seeing this in the first page now? – Vladimir May 20 '15 at 19:04

2 Answers2

1

This is a standard approach for other framework, e.g. Symfony/Laravel:

trans('error.validation');

But it has a downfall, if you forget to translate one phrase on your site it will appear like the keyword 'error.validation'

dynamic
  • 46,985
  • 55
  • 154
  • 231
1

In fact it doesn't matter!

It's just up to you.

However, I advise you do not split translations in sections. No there's any benefit in doing so. Actually, the most projects use the one file approach for all msgid entries. Like django, see.

Of course, If you still want split translation by sections, might you want take a look on Domains:

From PHP doc:

This function (textdomain()) sets the domain to search within when calls are made to gettext(), usually the named after an application.

Also, as earlier said, the advantage when using msgid as a real phrase ou word (instead underline or dotted notation key) is that it stays as default message if no there's a translation for entry.

And here goes some helpful links:

Community
  • 1
  • 1
felipsmartins
  • 13,269
  • 4
  • 48
  • 56