duandun2218 2015-03-03 15:08
浏览 26

Gettext在我的localhost上不起作用

I tried to start with gettext() but it doesn't work on my localhost.

My simple code:

<?php
$language='en';
putenv("LANG=$language"); 
setlocale(LC_ALL,$language);

$domain='test';
bindtextdomain($domain,"languages"); 
textdomain($domain);

echo _("Simple string to translate");

I have folder languages and in this folder another folder en but files are not creating. Thanks for help

  • 写回答

1条回答 默认 最新

  • doukuang6795 2015-06-13 13:21
    关注

    this is a good solution to set up your languages and call the translations from .po files. PHP is reading only .po so make sure to have that file's extension. In addition test your locale system if it is supporting the xy_XY format or the xy format: under linux use this line: locale -a and you will check how the locale is writed and supported. Under windows: check the system.io file.

    //get the location and set the languages
    define('SESSION_LOCALE_KEY', 'ix_locale');
    define('DEFAULT_LOCALE', 'en_US');
    define('LOCALE_REQUEST_PARAM', 'lang');
    define('WEBSITE_DOMAIN', 'messages');
    
    if (array_key_exists(LOCALE_REQUEST_PARAM, $_REQUEST)) {
        $current_locale = $_REQUEST[LOCALE_REQUEST_PARAM];
        $_SESSION[SESSION_LOCALE_KEY] = $current_locale;
    } elseif (array_key_exists(SESSION_LOCALE_KEY, $_SESSION)) {
        $current_locale = $_SESSION[SESSION_LOCALE_KEY];
    } else {
        $current_locale = DEFAULT_LOCALE;
    }
    
    putenv("LC_ALL=$current_locale");
    setlocale(LC_ALL, $current_locale);
    bindtextdomain(WEBSITE_DOMAIN, dirname(__FILE__) . '/lang');
    bind_textdomain_codeset(WEBSITE_DOMAIN, 'UTF-8');
    textdomain(WEBSITE_DOMAIN);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭