Browse Source

Repository*: first load language strings

master
parent
commit
c00d0a40eb
  1. 20
      src/RepositoryDir.php
  2. 20
      src/RepositoryGit.php

20
src/RepositoryDir.php

@ -17,6 +17,16 @@ class RepositoryDir extends RepositoryBase {
function data ($options) {
$data = parent::data($options);
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;
}
}
}
$d = opendir($this->path);
while ($f = readdir($d)) {
if (preg_match("/^([0-9a-zA-Z_\-]+)\.json$/", $f, $m) && $f !== 'package.json') {
@ -35,16 +45,6 @@ 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;
}

20
src/RepositoryGit.php

@ -32,6 +32,16 @@ class RepositoryGit extends RepositoryBase {
function data ($options) {
$data = parent::data($options);
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;
}
}
}
$d = popen("cd " . escapeShellArg($this->path) . "; git ls-tree {$this->branchEsc}", "r");
while ($r = fgets($d)) {
if (preg_match("/^[0-9]{6} blob [0-9a-f]{40}\t(([0-9a-zA-Z_\-]+)\.json)$/", $r, $m)) {
@ -57,16 +67,6 @@ 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