We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Internationalization, separate sets of template files or just one set


I want to translate an application to 2 other languages.

1- Should I:

  • Extract and put all terms in controllers (i.e. error messages etc.) and templates, and put them in language files? or
  • Have separate sets of templates for each language and then just extract terms in controllers and put them in separate language files?

Which approach is better? Why?

2- I find i18n support of phalcon a bit difficult to use (https://docs.phalcon.io/3.4/en/i18n) because it pollutes the code too much.

In my pure-php project I used to do this: I would build an associative array called "_L" (created inside a language file for each language). I would then use the array inside language file like this:

echo _L["user-account-created"];

can I use my own method? or i18n support of phalcon is better?

Thank you


if you use an array you could end up with a very large sum of values

for me i created a service and it loads different sets for each controller and a common set for all around usage and error handling

i never used phalcon's i18n

edited Mar '20

1) My vote would be to have a separate set of language files for each language. It'll make it much easier to maintain.

2) I've found Phalcon's language functionality a bit cumbersome too. All you're doing is loading data from an array and outputing a particular key, so custom functionality should be fine. I think a class might work better because then you can set the language used in the class and have it load the specific language files.

If you add that class as a service in the DI, you can then directly access it in the view. If your class implements the ArrayAccess interface, you can even use it like an array:

{{ _L['user-account-created'] }}

edited Mar '20


Thank you very much for excellent comment. It was very useful.

Just to clarify something. Do you suggest to also have separate set of Volt templates for each language?

I don't think you need to have separate templates. The point of the language files & class is to let you not care about language elsewhere.