I am trying to translate some texts to Japanese. But couldn't translate it. even it doesn't throw any error. according to https://www.php.net/manual/en/function.gettext.php bindtextdomain() should look for .mo file. when I debug my code ir returns /var/www/lumber-mill.co.jp/sys/locales
is it the problem of not being translated?
I followed these- PHP bindtextdomain fails
none of these solved my problem. How can I solve it?
<?php
function __autoload($class) {
$filename = dirname(__FILE__) . "/../core/" . $class . ".php";
if (file_exists($filename)) {
include_once $filename;
}else{
$filename = dirname(__FILE__) . "/../toolkit/" . $class . ".php";
if(file_exists($filename)){
include_once $filename;
}
}
}
// タイムゾーンと言語設定
date_default_timezone_set('Asia/Tokyo');
session_start();
if (isset($_GET["lang"])) {
// パラメタで直接指定されている場合
switch ($_GET["lang"]) {
case "en_US":
case "ja_JP":
$_SESSION["LANGUAGE"] = $_GET["lang"];
break;
default:
break;
}
} else if (!isset($_SESSION["LANGUAGE"])) {
// セッションに定義されていない場合、リクエストヘッダから判別します
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$languages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
$languages = array_reverse($languages);
} else {
$languages = array();
}
$lang = 'ja_JP'; // 規定値
foreach ($languages as $language) {
if (preg_match('/^ja/i', $language)) {
$lang = 'ja_JP';
} elseif (preg_match('/^en/i', $language)) {
$lang = 'en_US';
}
}
$_SESSION["LANGUAGE"] = $lang;
}
// 言語設定
setlocale(LC_ALL, $_SESSION["LANGUAGE"] . '.utf8');
$res = bindtextdomain("messages", $_SERVER["DOCUMENT_ROOT"]."/../sys/locales");
$mes = textdomain("messages");
bind_textdomain_codeset("messages", 'UTF-8');
print_r($res);
print_r($mes);
// 動作環境
if(strpos($_SERVER["SERVER_NAME"],"dev.") === 0){
define("ENV","staging");
}else{
define("ENV","production");
}
my problem was solved when I just added the following line-
putenv("LANGUAGE=".$_SESSION["LANGUAGE"].".utf8");