Flourish PHP Unframework
This is an archived copy of the forum for reference purposes

How to use I18N

posted by anonymous 8 years ago

There's an example using fText? I read the doc but I don't understand how to use. I want to create an app with several languages, Thanks!

Simple and dirty approach:

$translations = array(
    'en' => array(), // default language
    'de' => array(
        'Hello world!' => 'Hallo Welt!'
    ),
    'es' => array(
        'Hello world!' => 'Hola mundo!'
    )
);

function translate($string) {
    global $translations;
    
    /**
     * e.g. url?language=es or url?language=de
     * 
     * language should be store in session or cookie
    */
    
    $language = fRequest::getValid('language', array_keys($translations));
    
    return (isset($translations[$language][$string]))
        ? $translations[$language][$string]
        : $string;
}

fText::registerComposeCallback('pre', 'translate');

echo fText::compose('Hello world!');

In your layout/view file:

#!text/html
<p>
    <a href="url">English</a> |
    <a href="url?language=de">Deutsch</a> |
    <a href="url?language=es">Espaol</a>
</p>

)

posted by xoan 8 years ago

Thanks xoan! I'll try that source :)

posted by anonymous 8 years ago