Интернационализация и локализация в PHP, как разобраться?

Всем привет. Решил почитать про интернационализацию и локализацию на phprightway. В общем делаю всё по примеру (скорее мне так кажется), но ничего не выходит и меня терзают сомнения в том, как я понимаю.
Код из примера i18_setup.php

<?php
error_reporting(E_ALL);
/**
 * Verifies if the given $locale is supported in the project
 * @param string $locale
 * @return bool
 */
function valid($locale) {
   return in_array($locale, ['en_US', 'en', 'pt_BR', 'pt', 'es_ES', 'es', 'ru_Ru']);
}

//setting the source/default locale, for informational purposes
$lang = 'en_US';

if (isset($_GET['lang']) && valid($_GET['lang'])) {
	// the locale can be changed through the query-string
	$lang = $_GET['lang']; //you should sanitize this!
	setcookie('lang', $lang); //it's stored in a cookie so it can be reused
} elseif (isset($_COOKIE['lang']) && valid($_COOKIE['lang'])) {
	// if the cookie is present instead, let's just keep it
	$lang = $_COOKIE['lang'];
} elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
	$langs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
	array_walk($langs, function (&$lang) { $lang = strtr(strtok($lang, ';'), ['-' => '_']); });
	foreach ($langs as $browser_lang) {
		if (valid($browser_lang)) {
			$lang = $browser_lang;
			break;
		}
	}
}

// here we define the global system locale given the found language
putenv("LANG=$lang");

// this might be useful for date functions (LC_TIME) or money formatting (LC_MONETARY), for instance
setlocale(LC_ALL, $lang);

// this will make Gettext look for locales/<lang>/LC_MESSAGES/main.mo
bindtextdomain('main', 'locales');

// indicates in what encoding the file should be read
bind_textdomain_codeset('main', 'UTF-8');

// if your application has additional domains, as cited before, you should bind them here as well
bindtextdomain('forum', 'locales');
bind_textdomain_codeset('forum', 'UTF-8');

// here we indicate the default domain the gettext() calls will respond to
textdomain('main');

// this would look for the string in forum.mo instead of main.mo
// echo dgettext('forum', 'Welcome back!');


единственное тут добавил ru_Ru в массив функции valid

Это индекс

<?php include 'i18_setup.php'; ?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<div id="header">
		<?php
		$name = 'Alexey';
		$unread = 1;
		?>
		<h1><?php echo sprintf(gettext('Welcome, %s!'), $name); ?></h1>
		<?php if ($unread): ?>
			<h2>
				<?php
				echo sprintf(
					ngettext('Only one unread message',
							'%d unread messages',
							$unread),
					$unread
				);
				?>
			</h2>
		<?php endif; ?>
	</div>
	<h1><?php echo gettext('Introduction'); ?></h1>
	<p><?php echo gettext('We\'re now translation some string'); ?></p>
</body>
</html>


Далее, моя структура папок
5a1e56a8ebd64214831469.png

папка localization.loc это корень, там есть index.php. ну и соответственно тестовый перевод сделан

5a1e57203e97e242452212.png

перехожу по ссылке localization.loc/?lang=ru_Ru и вижу англ. текст. Понимаю, проблема, что я делаю что-то не так, прошу помочь или дайте ещё какую-нибудь детальную статью, т.к. походу на phprightway мне не особо понятно это было.

Заранее спасибо
  • Вопрос задан
  • 348 просмотров
Пригласить эксперта
Ответы на вопрос 1
DarkRaven
@DarkRaven
разработка программного обеспечения
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы