Skip to content

Commit

Permalink
Extract regions from resources/locales.json
Browse files Browse the repository at this point in the history
* fixes nextcloud/server#14822

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
  • Loading branch information
MorrisJobke committed Mar 25, 2019
1 parent cfbda91 commit f24eb13
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions translations/translationtool/src/translationtool.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@ class TranslatableApp {
private $name;
private $fakeAppInfoFile;
private $fakeVueFile;
private $fakeLocaleFile;
private $ignoreFiles;
private $translationsPath;

public function __construct($appPath, $translationsPath) {
public function __construct($appPath, $translationsPath) {
$this->appPath = $appPath;
$this->translationsPath = $translationsPath;

$this->ignoreFiles = [];
$this->fakeAppInfoFile = $this->appPath . '/specialAppInfoFakeDummyForL10nScript.php';
$this->fakeVueFile = $this->appPath . '/specialVueFakeDummyForL10nScript.js';
$this->fakeLocaleFile = $this->appPath . '/specialLocaleFakeDummyForL10nScript.php';

$this->setAppName();

Expand All @@ -57,12 +59,13 @@ public function __construct($appPath, $translationsPath) {
print_r($this->ignoreFiles);
}

public function createPotFile() {
public function createPotFile() {
$pathToPotFile = $this->translationsPath . '/templates/' . $this->name . '.pot';

// Gather required data
$this->createFakeFileForAppInfo();
$this->createFakeFileForVueFiles();
$this->createFakeFileForLocale();
$translatableFiles = $this->findTranslatableFiles(
['.php', '.js', '.jsx', '.html', '.ts', '.tsx'],
['.min.js']
Expand Down Expand Up @@ -98,6 +101,7 @@ public function createPotFile() {
// Don't forget to remove the temporary file
$this->deleteFakeFileForAppInfo();
$this->deleteFakeFileForVueFiles();
$this->deleteFakeFileForLocale();
}

public function createNextcloudFiles() {
Expand Down Expand Up @@ -372,6 +376,37 @@ private function setAppName() {
$this->name = $xml->id->__toString();
}
}

private function createFakeFileForLocale() {
if ($this->name !== 'settings') {
return false;
}
$entryName = $this->appPath . '/../resources/locales.json';

if (!file_exists($entryName)) {
return false;
}

$strings = [];
$locales = json_decode(file_get_contents($entryName), true);

foreach ($locales as $locale) {
$strings[] = $locale['name'];
}

$content = '<?php' . PHP_EOL;
foreach ($strings as $string) {
$content .= '$l->t(' . $this->escape($string) . ');' . PHP_EOL;
}

file_put_contents($this->fakeLocaleFile, $content);
}

private function deleteFakeFileForLocale() {
if (is_file($this->fakeLocaleFile)){
unlink($this->fakeLocaleFile);
}
}
}

class TranslationTool {
Expand Down
Binary file modified translations/translationtool/translationtool.phar
Binary file not shown.

0 comments on commit f24eb13

Please sign in to comment.