summaryrefslogtreecommitdiffstats
path: root/modules-available/translation/page.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/translation/page.inc.php')
-rw-r--r--modules-available/translation/page.inc.php75
1 files changed, 46 insertions, 29 deletions
diff --git a/modules-available/translation/page.inc.php b/modules-available/translation/page.inc.php
index a5cdebed..7d5229d7 100644
--- a/modules-available/translation/page.inc.php
+++ b/modules-available/translation/page.inc.php
@@ -53,11 +53,30 @@ class Page_Translation extends Page
private function loadCustomHandler($moduleName)
{
$path = 'modules/' . $moduleName . '/hooks/translation.inc.php';
- if (!file_exists($path))
- return false;
$HANDLER = array();
- require $path;
- return $HANDLER;
+ if (file_exists($path)) {
+ require $path;
+ }
+ $backup = $HANDLER;
+ foreach (glob('modules/*/hooks/translation-global.inc.php', GLOB_NOSORT) as $path) {
+ $HANDLER = array();
+ require $path;
+ if (empty($HANDLER['subsections']))
+ continue;
+ foreach ($HANDLER['subsections'] as $sub) {
+ $suf = '';
+ while (isset($backup['subsections']) && in_array($sub . $suf, $backup['subsections'])) {
+ $suf = mt_rand();
+ }
+ $backup['subsections'][] = $sub . $suf;
+ if (isset($HANDLER['grep_' . $sub])) {
+ $backup['grep_' . $sub . $suf] = $HANDLER['grep_' . $sub];
+ }
+ }
+ }
+ if (empty($backup))
+ return false;
+ return $backup;
}
/**
@@ -81,7 +100,7 @@ class Page_Translation extends Page
{
User::load();
- if (!User::hasPermission('superadmin')) {
+ if (!User::isLoggedIn()) {
Message::addError('main.no-permission');
Util::redirect('?do=Main');
}
@@ -445,19 +464,21 @@ class Page_Translation extends Page
$allFiles = array_merge($allFiles, $this->getAllFiles('apis', '.php'), $this->getAllFiles('inc', '.php'));
$allFiles[] = 'index.php';
}
- $tags = $this->loadTagsFromPhp('/Message\s*::\s*add\w+\s*\(\s*[\'"](?<module>[^\'"\.]*)\.(?<tag>[^\'"]*)[\'"]\s*(?<data>\)|\,.*)/i',
+ $full = $this->loadTagsFromPhp('/Message\s*::\s*add\w+\s*\(\s*[\'"](?<tag>[^\'"\.]*\.[^\'"]*)[\'"]\s*(?<data>\)|\,.*)/i',
$allFiles);
+ $tags = [];
// Filter out tags that don't refer to this module
- foreach (array_keys($tags) as $tag) {
+ foreach ($full as $tag) {
+ $p = explode('.', $tag['tag'], 2);
// Figure out if this is a message from this module or not
- if ($tags[$tag]['module'] === $module->getIdentifier()) {
+ if ($p[0] === $module->getIdentifier()) {
// Direct reference to this module via module.id
- continue;
+ $tag['tag'] = $p[1];
+ $tags[$p[1]] = $tag;
}
- unset($tags[$tag]);
}
- $tags += $this->loadTagsFromPhp('/Message\s*::\s*add\w+\s*\(\s*[\'"](?<tag>[^\'"\.]*)[\'"]\s*(?<data>\)|\,.*)/i',
- $this->getModulePhpFiles($module));
+ $tags = $this->loadTagsFromPhp('/Message\s*::\s*add\w+\s*\(\s*[\'"](?<tag>[^\'"\.]*)[\'"]\s*(?<data>\)|\,.*)/i',
+ $this->getModulePhpFiles($module), $tags);
return $tags;
}
@@ -812,12 +833,12 @@ class Page_Translation extends Page
*
* @param string $regexp regular expression
* @param array $files list of files to scan
+ * @param array $tags existing tag array to append to
* @return array of all tags found, where the tag is the key, and the value is as described above
*/
- private function loadTagsFromPhp($regexp, $files)
+ private function loadTagsFromPhp($regexp, $files, $tags = [])
{
// Get all php files, so we can find all strings that need to be translated
- $tags = array();
// Now find all tags in all php files. Only works for literal usage, not something like $foo = 'bar'; Dictionary::translate($foo);
foreach ($files as $file) {
$content = file_get_contents($file);
@@ -978,24 +999,20 @@ class Page_Translation extends Page
$data = array();
//find the tag requests to change the file
- foreach ($_POST as $key => $value) {
- $str = explode('#!#', $key, 2);
- if (count($str) !== 2)
+ $tags = Request::post('langtag', array(), 'array');
+ foreach ($tags as $tag => $value) {
+ error_log($tag . '=' . $value);
+ $tag = trim($tag);
+ if (empty($tag)) {
+ Message::addWarning('i18n-empty-tag');
continue;
- if ($str[0] === 'lang') {
- $tag = trim($str[1]);
- if (empty($tag)) {
- Message::addWarning('i18n-empty-tag');
- continue;
- }
- if (empty($value)) {
- unset($data[$tag]);
- } else {
- $data[$tag] = $value;
- }
+ }
+ if (empty($value)) {
+ unset($data[$tag]);
+ } else {
+ $data[$tag] = $value;
}
}
-
$translation = Request::post('new-text', array(), 'array');
foreach (Request::post('new-id', array(), 'array') as $k => $tag) {
if (empty($translation[$k]) || empty($tag))