mirror of
https://github.com/unraid/webgui.git
synced 2026-03-12 22:09:53 -05:00
Multi-language support
This commit is contained in:
@@ -78,6 +78,7 @@ $notes = " <a href='#' title='"._('View Release Notes')."' onclick=\"openBo
|
||||
</style>
|
||||
|
||||
<script src="<?autov('/webGui/javascript/dynamix.js')?>"></script>
|
||||
<script src="<?autov('/webGui/javascript/translations.js')?>"></script>
|
||||
<script>
|
||||
Shadowbox.init({skipSetup:true});
|
||||
|
||||
|
||||
@@ -59,7 +59,11 @@ case 'add':
|
||||
if ($result) exit(implode(',',$installed));
|
||||
case 'rm':
|
||||
$path = "$docroot/languages/$file";
|
||||
if ($result = is_dir($path)) {exec("rm -rf ".escapeshellarg($path)); @unlink("$boot/$file.lang.zip");}
|
||||
if ($result = is_dir($path)) {
|
||||
exec("rm -rf ".escapeshellarg($path));
|
||||
@unlink("$docroot/webGui/javascript/translations.js");
|
||||
@unlink("$boot/$file.lang.zip");
|
||||
}
|
||||
$installed = [];
|
||||
foreach (glob("$docroot/languages/*",GLOB_ONLYDIR) as $dir) $installed[] = basename($dir);
|
||||
if ($result) exit(implode(',',$installed));
|
||||
|
||||
@@ -79,21 +79,33 @@ $language = [];
|
||||
$locale = $_SESSION['locale'];
|
||||
|
||||
if ($locale) {
|
||||
$uri = explode('/',explode('?',$_SERVER['REQUEST_URI'])[0]);
|
||||
// split URI into translation levels
|
||||
$uri = array_filter(explode('/',strtok($_SERVER['REQUEST_URI'],'?')));
|
||||
$text = "$docroot/languages/$locale/translations.txt";
|
||||
if (file_exists($text)) {
|
||||
$data = "$docroot/languages/$locale/translations.dot";
|
||||
if (!file_exists($data)) file_put_contents($data,serialize(parse_lang_file($text)));
|
||||
$language = unserialize(file_get_contents($data));
|
||||
$basis = "$docroot/languages/$locale/translations.dot";
|
||||
$jsTxt = "$docroot/languages/$locale/javascript.txt";
|
||||
$jsOut = "$docroot/webGui/javascript/translations.js";
|
||||
// global translations
|
||||
if (!file_exists($basis)) file_put_contents($basis,serialize(parse_lang_file($text)));
|
||||
$language = unserialize(file_get_contents($basis));
|
||||
if (!file_exists($jsOut)) {
|
||||
// create javascript file with translations
|
||||
$source = file_exists($jsTxt) ? parse_lang_file($jsTxt) : [];
|
||||
$script = ['function _(t){var l={};'];
|
||||
foreach ($source as $key => $value) $script[] = "l[\"$key\"]=\"$value\";";
|
||||
$script[] ="return l[t.replace(/\&|[\?\{\}\|\&\~\!\[\]\(\)\/\\:\*^\.\"']|<.+?\/?>/g,'').replace(/ +/g,' ')]||t;}";
|
||||
file_put_contents($jsOut,implode('',$script));
|
||||
}
|
||||
}
|
||||
foreach($uri as $add) {
|
||||
if (!$add) continue;
|
||||
$add = strtolower($add);
|
||||
$text = "$docroot/languages/$locale/$add.txt";
|
||||
foreach($uri as $more) {
|
||||
$more = strtolower($more);
|
||||
$text = "$docroot/languages/$locale/$more.txt";
|
||||
if (file_exists($text)) {
|
||||
$data = "$docroot/languages/$locale/$add.dot";
|
||||
if (!file_exists($data)) file_put_contents($data,serialize(parse_lang_file($text)));
|
||||
$language = array_merge($language,unserialize(file_get_contents($data)));
|
||||
// additional translations
|
||||
$other = "$docroot/languages/$locale/$more.dot";
|
||||
if (!file_exists($other)) file_put_contents($other,serialize(parse_lang_file($text)));
|
||||
$language = array_merge($language,unserialize(file_get_contents($other)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user