aboutsummaryrefslogtreecommitdiff
path: root/cli/i18n/I18nFile.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2018-03-04 15:26:24 +0100
committerGravatar GitHub <noreply@github.com> 2018-03-04 15:26:24 +0100
commitf0fd273199682881b805e968ca36df4ccdbfa7a1 (patch)
tree0f87fcc515fb493193f9c58a9a0ed19f4caf07e8 /cli/i18n/I18nFile.php
parent5ebeb9e3e5d46195a83211140c1d28d58be19b2a (diff)
parenta37b95f6779e6e2035f0efb72cf5144e7fad2ea3 (diff)
Merge pull request #1810 from FreshRSS/dev1.10.1
FreshRSS 1.10.1
Diffstat (limited to 'cli/i18n/I18nFile.php')
-rw-r--r--cli/i18n/I18nFile.php31
1 files changed, 29 insertions, 2 deletions
diff --git a/cli/i18n/I18nFile.php b/cli/i18n/I18nFile.php
index d6489ee21..a07efdf88 100644
--- a/cli/i18n/I18nFile.php
+++ b/cli/i18n/I18nFile.php
@@ -36,8 +36,7 @@ class i18nFile {
}
foreach ($file as $name => $content) {
$filename = $dir . DIRECTORY_SEPARATOR . $name;
- $fullContent = var_export($this->unflatten($content), true);
- file_put_contents($filename, sprintf('<?php return %s;', $fullContent));
+ file_put_contents($filename, $this->format($content));
}
}
}
@@ -89,4 +88,32 @@ class i18nFile {
return $a;
}
+ /**
+ * Format an array of translation
+ *
+ * It takes an array of translation and format it to be dumped in a
+ * translation file. The array is first converted to a string then some
+ * formatting regexes are applied to match the original content.
+ *
+ * @param array $translation
+ * @return string
+ */
+ private function format($translation) {
+ $translation = var_export($this->unflatten($translation), true);
+ $patterns = array(
+ '/array \(/',
+ '/=>\s*array/',
+ '/ {2}/',
+ );
+ $replacements = array(
+ 'array(',
+ '=> array',
+ "\t", // Double quoting is mandatory to have a tab instead of the \t string
+ );
+ $translation = preg_replace($patterns, $replacements, $translation);
+
+ // Double quoting is mandatory to have new lines instead of \n strings
+ return sprintf("<?php\n\nreturn %s;\n", $translation);
+ }
+
}