已解决:Ubuntu php gettext 无效

it2025-04-09  12

使用gettext做多文字国际化,按PHP官方文档,在CentOS上OK,在Ubuntu上不行,调试了快1天,试了网上提供的无数方法,终于有一个OK了……

看到此文的同学别再被坑了……

 

感谢:http://stackoverflow.com/questions/18551553/php-gettext-translate-in-wrong-language-when-running-from-shell

BS官网文档:http://www.php.net/manual/en/function.gettext.php

 

代码:

<?php $lang = 'en_US'; //linux不支持zh-Hans,所以gettext、php都不支持。使用locale -a可以看到os支持的语言文字国家地区码。 putenv('LANGUAGE=' . $lang); //ubuntu 需要,centos不需要此行 setlocale(LC_ALL, $lang . '.utf8'); //ubuntu 需要.utf8,centos可有可无 $domain = 'strings'; bindtextdomain($domain, dirname(__FILE__) . '/locale'); bind_textdomain_codeset($domain , 'UTF-8'); textdomain($domain); echo _('asdf'); echo "\n"; exit; ?>

 

目录为en_US,如下:

| |--- | |---en_US | | |---LC_MESSAGES | | | |---strings.mo

 

转载于:https://www.cnblogs.com/sink_cup/p/ubuntu-php-gettext-error.html

相关资源:数据结构—成绩单生成器
最新回复(0)