how to use gettext in php?

后端 未结 3 1317
执念已碎
执念已碎 2021-01-22 12:59

I have a file dk.po and dk.mo in folder lang in my webdir.

How can I use this file? I have tried all, but I can not get it to work.

<         


        
3条回答
  •  一整个雨季
    2021-01-22 13:25

    this works for me my file is named messages.mo

    static function initialize_i18n() {
        $locale=App::$locale;        
        $locales_root = App::$root."locale";
        putenv('LANG='.$locale);
        putenv('LANGUAGE='.$locale);
        putenv('LC_ALL='.$locale);    
        putenv('LC_MESSAGES='.$locale); 
        setlocale(LC_ALL, $locale.".utf-8");   
        $domains = glob($locales_root.'/'.$locale.'/LC_MESSAGES/messages-*.mo');
        $current = basename($domains[0],'.mo');
        $timestamp = preg_replace('{messages-}i','',$current);
        bindtextdomain("messages",$locales_root);
        textdomain("messages");
    }    
    

提交回复
热议问题