Merge pull request #4657 from tomy0000000:master
🌐 Add Traditional Chinese Translation
This commit is contained in:
commit
f8d45de749
2
data/web/css/build/007-languages.min.css
vendored
2
data/web/css/build/007-languages.min.css
vendored
File diff suppressed because one or more lines are too long
@ -195,9 +195,65 @@ require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/sessions.inc.php';
|
||||
// Set language
|
||||
if (!isset($_SESSION['mailcow_locale']) && !isset($_COOKIE['mailcow_locale'])) {
|
||||
if ($DETECT_LANGUAGE && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
||||
$header_lang = strtolower(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2));
|
||||
if (array_key_exists($header_lang, $AVAILABLE_LANGUAGES)) {
|
||||
$_SESSION['mailcow_locale'] = $header_lang;
|
||||
// regex inspired from @GabrielAnderson on http://stackoverflow.com/questions/6038236/http-accept-language
|
||||
preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})*)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse);
|
||||
|
||||
$langs = $lang_parse[1];
|
||||
$ranks = $lang_parse[4];
|
||||
|
||||
// (create an associative array 'language' => 'preference')
|
||||
$lang2pref = array();
|
||||
for ($i=0; $i<count($langs); $i++) {
|
||||
$lang2pref[strtolower($langs[$i])] = (float) (!empty($ranks[$i]) ? $ranks[$i] : 1);
|
||||
}
|
||||
|
||||
// (comparison function for uksort)
|
||||
$cmpLangs = function ($a, $b) use ($lang2pref) {
|
||||
if ($lang2pref[$a] > $lang2pref[$b])
|
||||
return -1;
|
||||
elseif ($lang2pref[$a] < $lang2pref[$b])
|
||||
return 1;
|
||||
elseif (strlen($a) > strlen($b))
|
||||
return -1;
|
||||
elseif (strlen($a) < strlen($b))
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
};
|
||||
|
||||
// sort the languages by prefered language and by the most specific region
|
||||
uksort($lang2pref, $cmpLangs);
|
||||
|
||||
// generate language array without the region part
|
||||
$AVAILABLE_BASE_LANGUAGES=array();
|
||||
foreach ($AVAILABLE_LANGUAGES as $code => $lang) {
|
||||
$base_code = substr($code, 0, 2);
|
||||
if (!array_key_exists($base_code, $AVAILABLE_BASE_LANGUAGES)) {
|
||||
$AVAILABLE_BASE_LANGUAGES[$base_code] = $code;
|
||||
}
|
||||
}
|
||||
|
||||
// Find a perfect match or partial match
|
||||
// Match en-gb or en
|
||||
foreach ($lang2pref as $lang => $q) {
|
||||
if (array_key_exists($lang, $AVAILABLE_LANGUAGES)) {
|
||||
$_SESSION['mailcow_locale'] = $lang;
|
||||
break;
|
||||
} elseif (array_key_exists($lang, $AVAILABLE_BASE_LANGUAGES)) {
|
||||
$_SESSION['mailcow_locale'] = $AVAILABLE_BASE_LANGUAGES[$lang];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Try suggest match
|
||||
// e.g. suggest en-gb when only en-us is provided
|
||||
if (!isset($_COOKIE['mailcow_locale'])) {
|
||||
foreach ($lang2pref as $lang => $q) {
|
||||
if (array_key_exists(substr($lang, 0, 2), $AVAILABLE_BASE_LANGUAGES)) {
|
||||
$_SESSION['mailcow_locale'] = $AVAILABLE_BASE_LANGUAGES[substr($lang, 0, 2)];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -215,7 +271,7 @@ if (isset($_GET['lang']) && array_key_exists($_GET['lang'], $AVAILABLE_LANGUAGES
|
||||
/*
|
||||
* load language
|
||||
*/
|
||||
$lang = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/lang/lang.en.json'), true);
|
||||
$lang = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/lang/lang.en-gb.json'), true);
|
||||
|
||||
$langFile = $_SERVER['DOCUMENT_ROOT'] . '/lang/lang.'.$_SESSION['mailcow_locale'].'.json';
|
||||
if(file_exists($langFile)) {
|
||||
|
@ -76,33 +76,35 @@ $autodiscover_config = array(
|
||||
$DETECT_LANGUAGE = true;
|
||||
|
||||
// Change default language
|
||||
$DEFAULT_LANG = 'en';
|
||||
$DEFAULT_LANG = 'en-gb';
|
||||
|
||||
// Available languages
|
||||
// https://www.iso.org/obp/ui/#search
|
||||
// https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
|
||||
// https://en.wikipedia.org/wiki/IETF_language_tag
|
||||
$AVAILABLE_LANGUAGES = array(
|
||||
'cs' => 'Čeština (Czech)',
|
||||
'da' => 'Danish (Dansk)',
|
||||
'de' => 'Deutsch (German)',
|
||||
'en' => 'English',
|
||||
'es' => 'Español (Spanish)',
|
||||
'fi' => 'Suomi (Finish)',
|
||||
'fr' => 'Français (French)',
|
||||
'hu' => 'Magyar (Hungarian)',
|
||||
'it' => 'Italiano (Italian)',
|
||||
'ko' => '한국어 (Korean)',
|
||||
'lv' => 'latviešu (Latvian)',
|
||||
'nl' => 'Nederlands (Dutch)',
|
||||
'pl' => 'Język Polski (Polish)',
|
||||
'pt' => 'Português (Portuguese)',
|
||||
'ro' => 'Română (Romanian)',
|
||||
'ru' => 'Pусский (Russian)',
|
||||
'sk' => 'Slovenčina (Slovak)',
|
||||
'sv' => 'Svenska (Swedish)',
|
||||
'tr' => 'Türkçe (Turkish)',
|
||||
'uk' => 'Українська (Ukrainian)',
|
||||
'zh' => '中文 (Chinese)'
|
||||
// 'ca-es' => 'Català (Catalan)',
|
||||
'cs-cz' => 'Čeština (Czech)',
|
||||
'da-dk' => 'Danish (Dansk)',
|
||||
'de-de' => 'Deutsch (German)',
|
||||
'en-gb' => 'English',
|
||||
'es-es' => 'Español (Spanish)',
|
||||
'fi-fi' => 'Suomi (Finish)',
|
||||
'fr-fr' => 'Français (French)',
|
||||
'hu-hu' => 'Magyar (Hungarian)',
|
||||
'it-it' => 'Italiano (Italian)',
|
||||
'ko-kr' => '한국어 (Korean)',
|
||||
'lv-lv' => 'latviešu (Latvian)',
|
||||
'nl-nl' => 'Nederlands (Dutch)',
|
||||
'pl-pl' => 'Język Polski (Polish)',
|
||||
'pt-pt' => 'Português (Portuguese)',
|
||||
'ro-ro' => 'Română (Romanian)',
|
||||
'ru-ru' => 'Pусский (Russian)',
|
||||
'sk-sk' => 'Slovenčina (Slovak)',
|
||||
'sv-se' => 'Svenska (Swedish)',
|
||||
'tr-tr' => 'Türkçe (Turkish)',
|
||||
'uk-ua' => 'Українська (Ukrainian)',
|
||||
'zh-cn' => '简体中文 (Simplified Chinese)',
|
||||
'zh-tw' => '繁體中文 (Traditional Chinese)',
|
||||
);
|
||||
|
||||
// Change theme (default: lumen)
|
||||
|
1187
data/web/lang/lang.zh-tw.json
Normal file
1187
data/web/lang/lang.zh-tw.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -32,12 +32,12 @@
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
{% if mailcow_locale %}
|
||||
<li class="dropdown{% if available_languages|length == 1 %}lang-link-disabled{% endif %}">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><span class="flag-icon flag-icon-{{ mailcow_locale }}"></span><span class="caret"></span></a>
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><span class="flag-icon flag-icon-{{ mailcow_locale[-2:] }}"></span><span class="caret"></span></a>
|
||||
<ul class="dropdown-menu" role="menu">
|
||||
{% for key, val in available_languages %}
|
||||
<li{% if mailcow_locale == key %} class="active"{% endif %}>
|
||||
<a href="?{{ query_string({'lang': key}) }}">
|
||||
<span class="flag-icon flag-icon-{{ key }}"></span>{{ val }}
|
||||
<span class="flag-icon flag-icon-{{ key[-2:] }}"></span>{{ val }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
|
@ -45,13 +45,13 @@
|
||||
</div>
|
||||
{% if not oauth2_request %}
|
||||
<button type="button" {% if available_languages|length == 1 %}disabled="true"{% endif %} class="btn btn-xs-lg btn-default pull-right dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<span class="flag-icon flag-icon-{{ mailcow_locale }}"></span> <span class="caret"></span>
|
||||
<span class="flag-icon flag-icon-{{ mailcow_locale[-2:] }}"></span> <span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu pull-right login">
|
||||
{% for key, val in available_languages %}
|
||||
<li{% if mailcow_locale == key %} class="active"{% endif %}>
|
||||
<a href="?{{ query_string({'lang': key}) }}">
|
||||
<span class="flag-icon flag-icon-{{ key }}"></span>{{ val }}
|
||||
<span class="flag-icon flag-icon-{{ key[-2:] }}"></span>{{ val }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
|
@ -26,7 +26,7 @@ if(empty($targetLang)) {
|
||||
}
|
||||
|
||||
// load master lang
|
||||
$masterLang = file_get_contents(__DIR__.'/../data/web/lang/lang.en.json');
|
||||
$masterLang = file_get_contents(__DIR__.'/../data/web/lang/lang.en-gb.json');
|
||||
$masterLang = json_decode($masterLang, true);
|
||||
|
||||
// load target lang
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
MASTER="en"
|
||||
MASTER="en-gb"
|
||||
|
||||
DIR = "#{__dir__}/.."
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user