Search code examples
phplocalizationgettext

Is gettext the best way to localise a website in php? (only mild localisation needed)


Is gettext the best way to localise a website in php? I'm not using any frameworks, and there are not many words to translate, just two mildly different versions in English.


Solution

  • You can just use a lang_XX.php and include it in your application.

    $lang = array(
        "welcome" => "Welcome",
        "bye" => "Bye"
    );
    

    For other languages, say lang_fr.php, just have something like:

    $lang = array(
        "welcome" => "Accueil",
        "bye" => "Au revoir"
    );
    

    For a small use case, this should be fine and no need for going with .po files. Also, you can define it this way:

    function _($l)
    {
        return $lang[$l];
    }