Multi-lingual Support

https://olddocs.phalconphp.com/en/3.0.0/reference/translate.html

Why does this page shows only "NativeArray" adaper ?

Also NativeArray adapter description says:

"This is the best option in terms of performance."

Isn't gettext faster and better ?

Hi @costapmbo1997 there are other adapters in incubator repo. I'm using Db adapter with Intl, cache and icu formater and works fine.

Good luck

Isn't gettext faster and better ?

Not in every scenario. PHP still has to communicate with the gettext lib and db (even if cached). If you have a small list of phrases, NativaArray should actually be faster. BUT, that makes translations more hard to manage. Gettext has a nice ecosystem around it.



3.1k

Unfortunately Phalcon doesn't provide localization/translation solution. When it comes to above:

NativeArray

Appaling - I can't dump phrases, how to send it to translator and do you know a nice editor to native PHP arrays? And what about support? I don't even easily check missing translations. Performance? Good practice is to avoid large arrays, are arrays designed to store a data?

Db adapter

Appaling, the same reasons like above.

Gettext

Poor. "Gettext has a nice ecosystem around it" - sorry Lajos, but to my thinking it looks nowhere near as ecosystem, because it's native solution. You have to figure out many problems with language recognizing, setlocale function, dumping phrases (from .volt files or engine core) and still neither You nor your translator have any support.

Good translation system should include:

  • locale/language recognizing
  • supporting many and modern standards (like xliff)
  • dumping phrases by one command (like php phalcon translation --dump)
  • marking phrase as translated automatically (for instance each validator, flash message, etc.)
  • supporting (phrase context, missing phrases, similar/duplicate phrases etc.)

I've tested recently symfony + jms translations bundle and it's close to these goals. Unluckily I haven't encountered independent library yet.

Providing i18n functionality is NOT the role of Phalcon. Phalcon is an extensible framework, providing the bare minimums. And if you look at it from a performance point of view, it totally makes sense. Not everyone needs translations, and there's no point bloating the base framework with it. If you need a functionality, implement it.

NativeArray translations are designed to service small projects, where the translator is the developer.

DbAdapter is perfect for a site where you write translations using an admin page. The performance is bad, but usage is convenient.

Gettext is kind of an industry standard. There IS is a plethora of tools and transpilers and community sourced translation pages, where you upload the raw .po file and others translate it for you. You do need a tool to extract phrases from the source, but that's why you have tools like msgcat, msgconv msggrep, etc... And it's performance is excellent.

Every adapter provided by Phalcon has it's use case. Ignorance is not an excuse.