Best Approach in Multi Language Site

Hi,

I am looking to create a multi-language site using phalcon. I would like to seek some advices from experienced peeps who did it before on what is the best approach in doing so.

Cheer Derek

Its hard to say, can you be more specific, what exactly do you want achieve? Multilanguage models, how to handle translations, ...?



46.6k
edited Mar '16

I created Webird which has a lot of custom locale work. It also sports a nice Webpack locale system so that you can use the same Poedit tooling for the front and backend. xgettext has had PHP and Javascript support for some years now so you just need to be mindful of your front and backend templates. I added the Volt xgettext support to xgettext-template by modifying a similar template language. Front end xgettext message extraction is a hit or miss proposition that you will need to evaluate yourself.



6.5k

I use "symfony/translation". The best extension with PoEdit.

$di->setShared('translator', function() {
    $lang = Lang::getCurrentLanguage();

    $translator = new \Symfony\Component\Translation\Translator($lang, new \Symfony\Component\Translation\MessageSelector());
    $translator->setFallbackLocales(array('en_US'));
    $translator->addLoader('mo', new \Symfony\Component\Translation\Loader\MoFileLoader());

    if(file_exists(sprintf(__DIR__ . '/locale/%s.mo', $lang))) {
        $translator->addResource('mo', sprintf(__DIR__ . '/Resource/locale/%s.mo', $lang), $lang);
    } else {
        $translator->addResource('mo', __DIR__ . '/Resource/locale/en_US.mo', 'en_US');
    }


    return $translator;
});