diff --git a/repo.php b/repo.php index 6d1049d0..88aeba27 100644 --- a/repo.php +++ b/repo.php @@ -35,6 +35,9 @@ if (!isset($_REQUEST['repo'])) { $fullRepoId = $_REQUEST['repo']; list($repoId, $branchId) = explode('~', $fullRepoId); +if (array_key_exists('lang', $_REQUEST)) { + $fullRepoId .= '~' . $_REQUEST['lang']; +} if (!array_key_exists($repoId, $allRepositories)) { Header("HTTP/1.1 404 Repository not found"); diff --git a/src/OpenStreetBrowserLoader.js b/src/OpenStreetBrowserLoader.js index cb47e6ee..c4b35cd9 100644 --- a/src/OpenStreetBrowserLoader.js +++ b/src/OpenStreetBrowserLoader.js @@ -112,6 +112,7 @@ OpenStreetBrowserLoader.prototype.getRepo = function (repo, options, callback) { if (repo) { param.push('repo=' + encodeURIComponent(repo)) } + param.push('lang=' + encodeURIComponent(ui_lang)) param.push(config.categoriesRev) param = param.length ? '?' + param.join('&') : '' diff --git a/src/RepositoryBase.php b/src/RepositoryBase.php index 38eaabb0..be639208 100644 --- a/src/RepositoryBase.php +++ b/src/RepositoryBase.php @@ -28,6 +28,7 @@ class RepositoryBase { 'categories' => array(), 'templates' => array(), 'timestamp' => Date(DATE_ISO8601, $this->timestamp()), + 'lang' => array(), ); return $data; diff --git a/src/RepositoryDir.php b/src/RepositoryDir.php index 959998fa..86b82698 100644 --- a/src/RepositoryDir.php +++ b/src/RepositoryDir.php @@ -35,6 +35,16 @@ class RepositoryDir extends RepositoryBase { } closedir($d); + if (array_key_exists('lang', $options) && file_exists("{$this->path}/lang/{$options['lang']}.json")) { + $data['lang'] = json_decode(file_get_contents("{$this->path}/lang/en.json"), true); + $lang = json_decode(file_get_contents("{$this->path}/lang/{$options['lang']}.json"), true); + foreach ($lang as $k => $v) { + if ($v !== null && $v !== '') { + $data['lang'][$k] = $v; + } + } + } + return $data; } diff --git a/src/RepositoryGit.php b/src/RepositoryGit.php index 00b2f343..2040cf78 100644 --- a/src/RepositoryGit.php +++ b/src/RepositoryGit.php @@ -57,6 +57,16 @@ class RepositoryGit extends RepositoryBase { } pclose($d); + if (array_key_exists('lang', $options)) { + $data['lang'] = json_decode(shell_exec("cd " . escapeShellArg($this->path) . "; git show {$this->branchEsc}:lang/en.json 2>/dev/null"), true); + $lang = json_decode(shell_exec("cd " . escapeShellArg($this->path) . "; git show {$this->branchEsc}:lang/" . escapeShellArg("{$options['lang']}.json") . " 2>/dev/null"), true); + foreach ($lang as $k => $v) { + if ($v !== null && $v !== '') { + $data['lang'][$k] = $v; + } + } + } + if (!array_key_exists('branch', $this->def)) { $d = popen("cd " . escapeShellArg($this->path) . "; git for-each-ref --sort=-committerdate refs/heads/", "r"); $data['branch'] = $this->branch;