代码之家  ›  专栏  ›  技术社区  ›  ParisNakitaKejser

如何在PHP中使用gettext?

  •  2
  • ParisNakitaKejser  · 技术社区  · 16 年前

    我有文件 dk.po dk.mo 在我的webdir的lang文件夹中。

    如何使用此文件?我已经尽力了,但我不能让它发挥作用。

    // Lang
    putenv('LC_ALL=dk');
    setlocale(LC_ALL, 'dk');
    
    // Specify location of translation tables
    bindtextdomain("dk", ROOT .'lang');
    
    // Choose domain
    textdomain("dk");
    
    3 回复  |  直到 13 年前
        1
  •  5
  •   wesamly    16 年前

    我已经在用这个了:

    setlocale(LC_ALL, 'ar_LY.utf8');
    bindtextdomain("trans", $_SERVER["DOCUMENT_ROOT"].'/trans/locale');
    textdomain("trans"); 
    

    语言文件路径:

    /var/www/trans/locale/ar_LY/LC_MESSAGES/trans.mo
    

    我认为(不确定)你必须使用相同的路径!

        2
  •  2
  •   Luca Rocchi    16 年前

    这对我有用 我的文件名为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");
    }    
    
        3
  •  -1
  •   meder omuraliev    16 年前

    我会认真推荐使用 Zend_Translate 因为你可能会遇到很多与 locales 在各种类型的系统上。

    Docs: http://framework.zend.com/manual/en/zend.translate.using.html