niterain / PhpTalView

This package adds PHPTAL to Laravel
MIT License
3 stars 2 forks source link

Enhancement request: i18n #1

Closed towel closed 10 years ago

towel commented 10 years ago

Hi, I'd love to see GetText support for PhpTalEngine.

I made a simple implementation for this but am hesitant to issue a pull request because I'm new to Laravel4 and not sure about the config stuff.

/**
 * Enable GetText Translation
 * 
 * @param  mixed   $languages         language (string) or array of several languages
 * @param  string  $domain            GetText domain to use (basename for .mo+.po files)
 * @param  string  $translation_root  path where locales are located
 */
public function activateGetText($languages = null, $domain = "translations", $translation_root = null) 
{
    if($languages === null)
        $languages = [\Config::get('app.locale')];

    if(!is_array($languages))   
        $languages = [$languages];

    if($translation_root === null) 
        $translation_root = base_path() . "/locale/";

    $tr = new \PHPTAL_GetTextTranslator();

    call_user_func_array([$tr, "setLanguage"], $languages);
    $tr->addDomain($domain, $translation_root);
    $tr->useDomain($domain);

    $this->phptal->setTranslator($tr);

}

Could you maybe bake this properly into PhpTalView or inform me about needed changes for a possible pull request? Cheers!

niterain commented 10 years ago

I almost want to make this the setTranslator($language, $domain, $translator = '\PHPTAL_GetTextTranslator'), where the default parameter is GetTextTranslator

The translatorRoot, I would probably want to use app/lang as the default, but make the override configurable via the config file.

Other than that it looks fine. I have made several changes on my end to support a project I am currently working on. But since your post, I have added config settings translations, I also made a check that will override the local settings if you set them in the app/config/view.php Also added multiple skins by TEMPLATE_ID. Probably will be pushing out the changes tonight or tomorrow.

Thank you for the enhancement request.

towel commented 10 years ago

Please remove the echo statements!

Other than that, thanks a lot for the fast integration :)

niterain commented 10 years ago

Thanks towel.