Browse Source

Read a translation from repository

master
parent
commit
30367176c1
  1. 3
      repo.php
  2. 1
      src/OpenStreetBrowserLoader.js
  3. 1
      src/RepositoryBase.php
  4. 10
      src/RepositoryDir.php
  5. 10
      src/RepositoryGit.php

3
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");

1
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('&') : ''

1
src/RepositoryBase.php

@ -28,6 +28,7 @@ class RepositoryBase {
'categories' => array(),
'templates' => array(),
'timestamp' => Date(DATE_ISO8601, $this->timestamp()),
'lang' => array(),
);
return $data;

10
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;
}

10
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;

Loading…
Cancel
Save