Read available l10n files also from theme folder
The old behaviour was that only languages could be used for an app that are already present in the apps/$app/l10n folder. If there is a themed l10n that is not present in the apps default l10n folder the language could not be used and the texts are not translated. With this change this is possible and also the l10n files are loaded even if the default l10n doesn't contain the l10n file.
This commit is contained in:
parent
828cb08d49
commit
23c0f4ff5f
3 changed files with 49 additions and 7 deletions
|
@ -186,6 +186,23 @@ class Factory implements IFactory {
|
|||
}
|
||||
}
|
||||
|
||||
// merge with translations from theme
|
||||
$theme = $this->config->getSystemValue('theme');
|
||||
if (!empty($theme)) {
|
||||
$themeDir = \OC::$SERVERROOT . '/themes/' . $theme . substr($dir, strlen(\OC::$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;
|
||||
}
|
||||
|
@ -271,14 +288,14 @@ class Factory implements IFactory {
|
|||
&& 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 = \OC::$SERVERROOT . '/themes/' . $theme . substr($transFile, strlen(\OC::$SERVERROOT));
|
||||
if (file_exists($transFile)) {
|
||||
$languageFiles[] = $transFile;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
0
tests/data/themes/abc/apps/files/l10n/zz.json
Normal file
0
tests/data/themes/abc/apps/files/l10n/zz.json
Normal file
|
@ -287,6 +287,31 @@ class FactoryTest extends TestCase {
|
|||
];
|
||||
}
|
||||
|
||||
public function testFindAvailableLanguagesWithThemes() {
|
||||
$serverRoot = \OC::$SERVERROOT;
|
||||
\OC::$SERVERROOT = \OC::$SERVERROOT . '/tests/data';
|
||||
$app = 'files';
|
||||
|
||||
$factory = $this->getFactory(['findL10nDir']);
|
||||
$factory->expects($this->once())
|
||||
->method('findL10nDir')
|
||||
->with($app)
|
||||
->willReturn(\OC::$SERVERROOT . '/apps/files/l10n/');
|
||||
$this->config
|
||||
->expects($this->once())
|
||||
->method('getSystemValue')
|
||||
->with('theme')
|
||||
->willReturn('abc');
|
||||
|
||||
try {
|
||||
$this->assertEquals(['en', 'zz'], $factory->findAvailableLanguages($app), '', 0.0, 10, true);
|
||||
} catch (\Exception $e) {
|
||||
\OC::$SERVERROOT = $serverRoot;
|
||||
throw $e;
|
||||
}
|
||||
\OC::$SERVERROOT = $serverRoot;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataLanguageExists
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue