Multi-Language: best way?

HI

Which tool/way is the best for creating a multi-lang project in phalcon? (gettext, PO, NativeArray, CSV, ...)

I consider performance at all

If you want native Phalcon multi-lingual functionality, there is Phalcon\Translate available: https://docs.phalconphp.com/en/latest/reference/translate.html

and there's extra adapters on Incubator https://github.com/phalcon/incubator/tree/master/Library/Phalcon/Translate/Adapter for more logical usage.

edited Jul '15

thanks for your response.

sorry, I edited my question.

  • which is better?

>If you want native Phalcon multi-lingual functionality, there is Phalcon\Translate available: https://docs.phalconphp.com/en/latest/reference/translate.html > >and there's extra adapters on Incubator https://github.com/phalcon/incubator/tree/master/Library/Phalcon/Translate/Adapter for more logical usage.



47.5k
edited Jul '15

gettext extracts messages and saves them in a PO file. Its nice because it will pull the strings out of the code and templates so that you don't have to manually populate the keys. I've found that including the English string in the message is the best way because then the translator (person) is automatically made aware of any changes. So use "Hello World" instead of "hello_world". You can use Jed on the Javascript side to do the same thing and the message extractor xgettext that comes with gettext has built in Javascipt (and PHP) parsing. Templates are hit and miss and you need to make sure that there is a parser available so often you will end up looking for similar template systems to base on if you can't find one. There are parsers for Mustache and I've worked towards getting a Volt parser into xgettext-template but I need to finish that effort as of the moment I'm using it from under my personal github account.

Next thing is that there is a new Javascript web standard for translation that takes into account all sorts of special language cases. I'm not a linguist so simply having N cases for the number of plural forms in each language is enough for me. So PO technology isn't the latest or most powerful but the tooling is well established and I found the other options to be maddening.

I've worked out a lot of integration between Phalcon and Javascript (Webpack) in my Webird framework. I must say that it was no small effort. One difficult part is having your build system package up all of the PO files into JSON and then having the browser Javascript determine the best language match and then asyncronously downloading the correct language file, pushing it into Jed and then signalling the rest of the app to continue loading. I've worked all of that out in Webird with the simple po-loader that I created for Webpack. Also check out the locale module.