mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
gettext is working with browsers language
This commit is contained in:
@@ -39,12 +39,15 @@ defined('LC_MESSAGES') or define('LC_MESSAGES', 5);
|
||||
|
||||
require('inc/streams.php');
|
||||
require('inc/gettext_reader.php');
|
||||
require_once('gettext_conf.php');
|
||||
|
||||
// Variables
|
||||
|
||||
global $text_domains, $default_domain, $LC_CATEGORIES, $EMULATEGETTEXT, $CURRENTLOCALE;
|
||||
global $text_domains, $default_domain, $default_lang, $available_languages, $gt_conf, $LC_CATEGORIES, $EMULATEGETTEXT, $CURRENTLOCALE;
|
||||
$text_domains = array();
|
||||
$default_domain = 'installer';
|
||||
$default_domain = $gt_conf['default_domain'];
|
||||
$default_lang = $gt_conf['default_lang'];
|
||||
$available_languages = $gt_conf['languages'];
|
||||
$LC_CATEGORIES = array(
|
||||
'LC_CTYPE',
|
||||
'LC_NUMERIC',
|
||||
@@ -65,6 +68,36 @@ class domain {
|
||||
|
||||
// Utility functions
|
||||
|
||||
/**
|
||||
* Get the clients language from the browser
|
||||
*/
|
||||
|
||||
function _get_client_language() {
|
||||
global $default_lang;
|
||||
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
||||
$code = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
|
||||
$lang = find_by('code', $code) ?: $default_lang;
|
||||
} else {
|
||||
$code = 'en';
|
||||
$lang = find_by('code', $code);
|
||||
}
|
||||
return $lang;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the correct language by different parameters
|
||||
*/
|
||||
|
||||
function find_by($field = 'folder', $match = 'english') {
|
||||
global $available_languages;
|
||||
foreach ($available_languages as $lang) {
|
||||
if (isset($lang[$field]) && $lang[$field] === $match) {
|
||||
return $lang;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of locales to try for any POSIX-style locale specification.
|
||||
*/
|
||||
|
||||
@@ -10,11 +10,13 @@
|
||||
|
||||
|
||||
|
||||
$gt_conf['gt_install_domain'] = 'installer';
|
||||
$gt_conf['default_domain'] = 'installer';
|
||||
|
||||
$gt_conf['gt_install_cookie'] = 'installer_language';
|
||||
$gt_conf['default_lang'] = 'english';
|
||||
|
||||
$gt_conf['gt_install_languages'] = array(
|
||||
$gt_conf['lang_cookie'] = 'install_lang';
|
||||
|
||||
$gt_conf['languages'] = array(
|
||||
|
||||
'bulgarian' => array(
|
||||
'name' => 'Български',
|
||||
|
||||
@@ -25,14 +25,8 @@ if (file_exists('config_unattended.php')) {
|
||||
require_once('includes/gettext/gettext.php');
|
||||
require_once('includes/gettext/gettext_conf.php');
|
||||
|
||||
|
||||
|
||||
// define('LOCALE_DIR', 'includes/gettext/locale');
|
||||
define('DEFAULT_LOCALE', 'de_DE');
|
||||
|
||||
$language = (isset($_GET['lang'])) ? $_GET['lang'] : DEFAULT_LOCALE;
|
||||
|
||||
T_setlocale(LC_MESSAGES, $language);
|
||||
$language = _get_client_language();
|
||||
T_setlocale(LC_MESSAGES, $language['gettext']);
|
||||
|
||||
// #########################################################
|
||||
// PRECONFIGURATION
|
||||
@@ -181,7 +175,7 @@ global $wavelog_url;
|
||||
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="<?= $language; ?>">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="<?= $language['gettext']; ?>">
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
@@ -1498,4 +1492,25 @@ global $wavelog_url;
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Hidden field to be able to translate the language names
|
||||
Add english Language Name here if you add new languages to application/config/gettext.php
|
||||
This helps the po scanner -->
|
||||
<div style="display: none">
|
||||
<?= __("Bulgarian"); ?>
|
||||
<?= __("Chinese (Simplified)"); ?>
|
||||
<?= __("Czech"); ?>
|
||||
<?= __("Dutch"); ?>
|
||||
<?= __("English"); ?>
|
||||
<?= __("Finnish"); ?>
|
||||
<?= __("French"); ?>
|
||||
<?= __("German"); ?>
|
||||
<?= __("Greek"); ?>
|
||||
<?= __("Italian"); ?>
|
||||
<?= __("Polish"); ?>
|
||||
<?= __("Russian"); ?>
|
||||
<?= __("Spanish"); ?>
|
||||
<?= __("Swedish"); ?>
|
||||
<?= __("Turkish"); ?>
|
||||
</div>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user