feat: improve language recognition and alias handling
Updated browser language detection to handle full locale strings and mapped various Chinese variants to simplified or traditional Chinese. Renamed language files for consistency with the new alias system. This improves support for a wider array of language settings, ensuring users receive content in their preferred language variant when possible.
This commit is contained in:
parent
d18fcd803c
commit
25f6bb423e
2 changed files with 29 additions and 8 deletions
35
index.php
35
index.php
|
@ -43,10 +43,8 @@ foreach ($currencies as $currency) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the browser language
|
// Get the browser language
|
||||||
$lang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) : "en";
|
$lang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : "en";
|
||||||
if ($lang == 'zh' || $lang == 'pt') {
|
$lang = strtolower($lang);
|
||||||
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scan the lang/ directory for available language files
|
// Scan the lang/ directory for available language files
|
||||||
$langFiles = glob('lang/*.php');
|
$langFiles = glob('lang/*.php');
|
||||||
|
@ -56,11 +54,34 @@ foreach ($langFiles as $file) {
|
||||||
$acceptLang[] = strtolower($langCode);
|
$acceptLang[] = strtolower($langCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the browser language is available, otherwise use English
|
// Aliases for different Chinese variants
|
||||||
$lang = in_array($lang, $acceptLang) ? $lang : 'en';
|
$aliases = [
|
||||||
$lang = strtolower($lang);
|
'zh' => 'zh-hans',
|
||||||
|
'zh-hk' => 'zh-hant',
|
||||||
|
'zh-tw' => 'zh-hant',
|
||||||
|
'zh-cn' => 'zh-hans',
|
||||||
|
'zh-sg' => 'zh-hans',
|
||||||
|
'zh-mo' => 'zh-hant',
|
||||||
|
];
|
||||||
|
|
||||||
|
if (isset($aliases[$lang])) {
|
||||||
|
$lang = $aliases[$lang];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the browser language is supported
|
||||||
|
if (!in_array($lang, $acceptLang)) {
|
||||||
|
// Try again without the region code (if present, e.g. en-US -> en)
|
||||||
|
$lang = explode('-', $lang)[0];
|
||||||
|
if (!in_array($lang, $acceptLang)) {
|
||||||
|
// Default to English if the browser language is not supported
|
||||||
|
$lang = 'en';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
require_once "lang/{$lang}.php";
|
require_once "lang/{$lang}.php";
|
||||||
|
|
||||||
|
// Calculation through GET parameters
|
||||||
|
|
||||||
$xmr_in = isset($_GET["in"]) ? strtoupper(htmlspecialchars($_GET["in"])) : 'EUR';
|
$xmr_in = isset($_GET["in"]) ? strtoupper(htmlspecialchars($_GET["in"])) : 'EUR';
|
||||||
$xmr_amount = isset($_GET["xmr"]) ? floatval($_GET["xmr"]) : 1;
|
$xmr_amount = isset($_GET["xmr"]) ? floatval($_GET["xmr"]) : 1;
|
||||||
$fiat_amount = isset($_GET["fiat"]) ? floatval($_GET["fiat"]) : '';
|
$fiat_amount = isset($_GET["fiat"]) ? floatval($_GET["fiat"]) : '';
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php // Translator: Winslow SorenEricMent(逸雩)
|
<?php // Translator: Winslow SorenEricMent(逸雩)
|
||||||
// For the HTML meta specification, e.g. <!DOCTYPE html><html lang="en">
|
// For the HTML meta specification, e.g. <!DOCTYPE html><html lang="en">
|
||||||
$lang_meta = "zh"; // https://www.w3schools.com/tags/ref_language_codes.asp
|
$lang_meta = "zh-Hans"; // https://www.w3schools.com/tags/ref_language_codes.asp
|
||||||
|
|
||||||
$page_title = "门罗币与欧元/BTC/CHF/美元等币种汇率"; // The browser tab title or search engine title
|
$page_title = "门罗币与欧元/BTC/CHF/美元等币种汇率"; // The browser tab title or search engine title
|
||||||
$meta_description = "门罗币实时多币种汇率,免费提供。"; // Search engine description / text
|
$meta_description = "门罗币实时多币种汇率,免费提供。"; // Search engine description / text
|
Loading…
Reference in a new issue