-
-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement localization loader L10N. Localize a few strings in index.php for testing. * Determine language from HTTP_ACCEPT_LANGUAGE header. * Fix parsing of available languages for localization. * Fix parsing of language translations (for localization). * Fix function L10N->find_language * Change variable naming to comply with conventions. * Add remaining localize calls in index.php. Add more localization strings. * Fix styles to prevent check mark from being hidden. * Handle exception in case localization couldn't be loaded. * Add module localization support. * Fix detection of core module in L10N->load * Remove module specific localization from core l10n file. * Fix determination of module name in L10N->load. * Add localization files for more modules. * Ignore l10n directory in modules path. * Add support for dropdown lists in module settings. * Add support for saving dropdown menus. * Fix regex for recognizing dropdown option lists. * Fix dropdown list regex not recognizing active option. * Fix typo in ncp-launcher.php * Workaround for jquery's 'find' method not working. //TODO: Find proper fix. * Fix parsing of dropdown lists when updating config. * Load language setting from config if available. * add ncp-provisioning to SD card images * Add intellij config to gitignore * Fix bug when loading language from nc-webui config. * Remove redundant language definition. Replace umlauts by html special char expressions. * Change selected option markup from `*<option>*` to `_<option>_`. * Remove ide metadata. * Add translations for ncp-app nc-backup. * Add translation hooks to ncp-launcher.php * Fix type in translations for nc-backup * Remove translation hooks for field contents in ncp-launcher.php
- Loading branch information
1 parent
c4a111c
commit 1a7c8b9
Showing
44 changed files
with
385 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
.*.swp | ||
*.img | ||
*.bz2 | ||
.idea/ | ||
qemu-raspbian-network/ | ||
torrent/ | ||
armbian/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"translations": { | ||
"nc-audit": "Sicherheitsüberprüfung" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"translations": { | ||
"nc-automount": "Automatische Datenträgereinbindung" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"translations": { | ||
"nc-autoupdate-ncp": "Automatische NextCloudPi Updates" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"translations": { | ||
"nc-backup-auto": "Automatische Backups" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{"translations": { | ||
"nc-backup": "Backup erstellen", | ||
"DESTDIR": "Zielverzeichnis", | ||
"INCLUDEDATA": "Inkl. Dateien", | ||
"COMPRESS": "Komprimieren", | ||
"BACKUPLIMIT": "Maximale Anzahl" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"translations": { | ||
"nc-database": "Datenbank" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"translations": { | ||
"nc-datadir": "Datenverzeichnis" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"translations": { | ||
"nc-export-ncp": "NCP Export" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"translations": { | ||
"nc-fix-permissions": "Berechtigungen wiederherstellen" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"translations": { | ||
"nc-format-USB": "USB Laufwerke formatieren" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"translations": { | ||
"nc-forward-ports": "Portweiterleitungen" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"translations": { | ||
"nc-httpsonly": "HTTPS Zwang" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"translations": { | ||
"nc-import-ncp": "NCP Import" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"translations": { | ||
"nc-info": "System Informationen" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"translations": { | ||
"nc-init": "Initialisierung" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"translations": { | ||
"nc-limits": "Systembegrenzungen" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"translations": { | ||
"nc-nextcloud": "Nextcloud Einstellungen" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"translations": { | ||
"nc-notify-updates": "Update-Benachrichtigungen" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"translations": { | ||
"nc-passwd": "NCP Passwort" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"translations": { | ||
"nc-ramlogs": "Ram Logs" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"translations": { | ||
"nc-restore": "Wiederherstellung" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"translations": { | ||
"nc-scan-auto": "Automatischer Datei-Scan" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"translations": { | ||
"nc-scan": "Datei-Scan" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"translations": { | ||
"nc-snapshot-auto": "Automatische Snapshots" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"translations": { | ||
"nc-snapshot": "Snapshot erstellen" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"translations": { | ||
"nc-static-IP": "Statische IP Adresse" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"translations": { | ||
"nc-swapfile": "Swap Datei" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"translations": { | ||
"nc-update": "Update" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"translations": { | ||
"nc-webui": "NCP Weboberfläche" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"translations": { | ||
"nc-wifi": "WLAN" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"translations": { | ||
"unattended-upgrades": "Unüberwachte System-Upgrades" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<?php | ||
|
||
class L10N { | ||
private $translations = []; | ||
const default_language = "en_US"; | ||
private $language; | ||
|
||
public function __construct($desired_languages, $l10n_dir, $modules_path=null) | ||
{ | ||
if (!isset($desired_languages)) { | ||
$desired_languages = ""; | ||
} | ||
|
||
$l10n_dir = rtrim($l10n_dir, '/'); | ||
$available_languages = array_filter(scandir($l10n_dir), | ||
function ($s) { | ||
return pathinfo($s, PATHINFO_EXTENSION) == "json"; | ||
}); | ||
$available_languages = array_map( | ||
function ($s) { | ||
return basename($s, ".json"); | ||
}, | ||
$available_languages); | ||
|
||
$desired_lang = $this->load_language_setting($modules_path); | ||
if($desired_lang != "auto") | ||
{ | ||
$desired_languages = $desired_lang; | ||
} | ||
$lang = $this->find_language($available_languages, $desired_languages); | ||
$this->language = $lang; | ||
if ($lang === L10N::default_language || !file_exists(join('/', [$l10n_dir, $lang . ".json"])) || !$this->load($lang, $l10n_dir, $modules_path)) { | ||
$this->language = L10N::default_language; | ||
} | ||
} | ||
|
||
function load($lang, $l10n_dir, $modules_path) | ||
{ | ||
$modules_path = join('/', [rtrim($modules_path, '/'), $l10n_dir]); | ||
$files = [join('/', [$l10n_dir, $lang . ".json"])]; | ||
if (is_dir($modules_path)) { | ||
foreach (scandir($modules_path) as $dir) { | ||
$file_path = join('/', [$modules_path, trim($dir, '/'), $lang . ".json"]); | ||
if (is_file($file_path)) { | ||
array_push($files, $file_path); | ||
} | ||
} | ||
} | ||
|
||
$jsonError = null; | ||
foreach ($files as $file) { | ||
$module_name = pathinfo(pathinfo($file, PATHINFO_DIRNAME), PATHINFO_BASENAME); | ||
if( $module_name == pathinfo($l10n_dir, PATHINFO_BASENAME)) { | ||
$module_name = "__core__"; | ||
} | ||
$json = json_decode(file_get_contents($file), true); | ||
if (!is_array($json)) { | ||
$jsonError = json_last_error(); | ||
continue; | ||
} | ||
$this->translations[$module_name] = $json['translations']; | ||
} | ||
return ($jsonError == null); | ||
} | ||
|
||
public function __($text, $module="__core__") { | ||
if( isset($this->translations[$module]) && isset($this->translations[$module][$text])) { | ||
return $this->translations[$module][$text]; | ||
} | ||
return $text; | ||
} | ||
|
||
function find_language(array $available_languages, $desired_language) { | ||
|
||
$available_languages = array_flip($available_languages); | ||
$langs = []; | ||
preg_match_all('~([\w-]+)(?:[^,\d]+([\d.]+))?~', strtolower($desired_language), $matches, PREG_SET_ORDER); | ||
|
||
foreach($matches as $match) { | ||
|
||
list($a, $b) = explode('-', $match[1]) + array('', ''); | ||
$value = isset($match[2]) ? (float) $match[2] : 1.0; | ||
|
||
if(isset($available_languages[$match[1]])) { | ||
$langs[$match[1]] = $value; | ||
continue; | ||
} | ||
|
||
if(isset($available_languages[$a])) { | ||
$langs[$a] = $value - 0.1; | ||
} | ||
|
||
} | ||
arsort($langs); | ||
|
||
if(count($langs) == 0) { | ||
return L10N::default_language; | ||
} | ||
return array_keys($langs)[0]; | ||
} | ||
|
||
function load_language_setting($modules_path) { | ||
$webui_config_file = join('/', [rtrim($modules_path, '/'), 'nc-webui.sh']); | ||
$fh = fopen( $webui_config_file ,'r') | ||
or exit( '{ "output": "' . $webui_config_file . ' read error" }' ); | ||
$lang = "auto"; | ||
while ( $line = fgets($fh) ) | ||
{ | ||
// drop down menu | ||
if(preg_match('/^LANGUAGE_=\[(([_\w]+,)*[_\w]+)\]$/', $line, $matches)) | ||
{ | ||
$options = explode(',', $matches[1]); | ||
foreach($options as $option) | ||
{ | ||
if($option[0] == "_" && $option[count($option) - 1] == "_") | ||
{ | ||
fclose($fh); | ||
$lang = trim($option,'_'); | ||
} | ||
} | ||
fclose($fh); | ||
return $lang; | ||
} | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.