summaryrefslogtreecommitdiffstats
path: root/lib/private/l10n/factory.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/l10n/factory.php')
-rw-r--r--lib/private/l10n/factory.php61
1 files changed, 41 insertions, 20 deletions
diff --git a/lib/private/l10n/factory.php b/lib/private/l10n/factory.php
index 1440e9510c5..8f157d9c0bb 100644
--- a/lib/private/l10n/factory.php
+++ b/lib/private/l10n/factory.php
@@ -64,17 +64,23 @@ class Factory implements IFactory {
/** @var IUserSession */
protected $userSession;
+ /** @var string */
+ protected $serverRoot;
+
/**
* @param IConfig $config
* @param IRequest $request
* @param IUserSession $userSession
+ * @param string $serverRoot
*/
public function __construct(IConfig $config,
IRequest $request,
- IUserSession $userSession) {
+ IUserSession $userSession,
+ $serverRoot) {
$this->config = $config;
$this->request = $request;
$this->userSession = $userSession;
+ $this->serverRoot = $serverRoot;
}
/**
@@ -89,20 +95,18 @@ class Factory implements IFactory {
if ($lang !== null) {
$lang = str_replace(array('\0', '/', '\\', '..'), '', (string) $lang);
}
- $key = $lang;
- if ($key === null || !$this->languageExists($app, $lang)) {
- $key = 'null';
+ if ($lang === null || !$this->languageExists($app, $lang)) {
$lang = $this->findLanguage($app);
}
- if (!isset($this->instances[$key][$app])) {
- $this->instances[$key][$app] = new L10N(
+ if (!isset($this->instances[$lang][$app])) {
+ $this->instances[$lang][$app] = new L10N(
$this, $app, $lang,
$this->getL10nFilesForApp($app, $lang)
);
}
- return $this->instances[$key][$app];
+ return $this->instances[$lang][$app];
}
/**
@@ -186,6 +190,23 @@ class Factory implements IFactory {
}
}
+ // merge with translations from theme
+ $theme = $this->config->getSystemValue('theme');
+ if (!empty($theme)) {
+ $themeDir = $this->serverRoot . '/themes/' . $theme . substr($dir, strlen($this->serverRoot));
+
+ if (is_dir($themeDir)) {
+ $files = scandir($themeDir);
+ if ($files !== false) {
+ foreach ($files as $file) {
+ if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') {
+ $available[] = substr($file, 0, -5);
+ }
+ }
+ }
+ }
+ }
+
$this->availableLanguages[$key] = $available;
return $available;
}
@@ -263,22 +284,22 @@ class Factory implements IFactory {
$i18nDir = $this->findL10nDir($app);
$transFile = strip_tags($i18nDir) . strip_tags($lang) . '.json';
- if ((\OC_Helper::isSubDirectory($transFile, \OC::$SERVERROOT . '/core/l10n/')
- || \OC_Helper::isSubDirectory($transFile, \OC::$SERVERROOT . '/lib/l10n/')
- || \OC_Helper::isSubDirectory($transFile, \OC::$SERVERROOT . '/settings/l10n/')
+ if ((\OC_Helper::isSubDirectory($transFile, $this->serverRoot . '/core/l10n/')
+ || \OC_Helper::isSubDirectory($transFile, $this->serverRoot . '/lib/l10n/')
+ || \OC_Helper::isSubDirectory($transFile, $this->serverRoot . '/settings/l10n/')
|| \OC_Helper::isSubDirectory($transFile, \OC_App::getAppPath($app) . '/l10n/')
)
&& file_exists($transFile)) {
// load the translations file
$languageFiles[] = $transFile;
+ }
- // merge with translations from theme
- $theme = $this->config->getSystemValue('theme');
- if (!empty($theme)) {
- $transFile = \OC::$SERVERROOT . '/themes/' . $theme . substr($transFile, strlen(\OC::$SERVERROOT));
- if (file_exists($transFile)) {
- $languageFiles[] = $transFile;
- }
+ // merge with translations from theme
+ $theme = $this->config->getSystemValue('theme');
+ if (!empty($theme)) {
+ $transFile = $this->serverRoot . '/themes/' . $theme . substr($transFile, strlen($this->serverRoot));
+ if (file_exists($transFile)) {
+ $languageFiles[] = $transFile;
}
}
@@ -293,14 +314,14 @@ class Factory implements IFactory {
*/
protected function findL10nDir($app = null) {
if (in_array($app, ['core', 'lib', 'settings'])) {
- if (file_exists(\OC::$SERVERROOT . '/' . $app . '/l10n/')) {
- return \OC::$SERVERROOT . '/' . $app . '/l10n/';
+ if (file_exists($this->serverRoot . '/' . $app . '/l10n/')) {
+ return $this->serverRoot . '/' . $app . '/l10n/';
}
} else if ($app && \OC_App::getAppPath($app) !== false) {
// Check if the app is in the app folder
return \OC_App::getAppPath($app) . '/l10n/';
}
- return \OC::$SERVERROOT . '/core/l10n/';
+ return $this->serverRoot . '/core/l10n/';
}