aboutsummaryrefslogtreecommitdiff
path: root/cli/i18n/I18nIgnoreFile.php
diff options
context:
space:
mode:
authorGravatar Alexis Degrugillier <aledeg@users.noreply.github.com> 2022-01-08 08:00:26 -0500
committerGravatar GitHub <noreply@github.com> 2022-01-08 14:00:26 +0100
commit127b7f0a3aad7012055c058e8aba0d27192a8cbc (patch)
tree8ec9a5948672e702c944c202f78294b81104582f /cli/i18n/I18nIgnoreFile.php
parented19445f74c30854c60873cd1df1c38e15fc316b (diff)
Change i18n process (#4131)
Before, the ignore info were stored in a different file which was a bit cumbersome for new comers. Now, this info is stored directly in the translation file as a comment. Before, there was no way of telling translators that a previously translated string was in need of a new translation. Now, the dirty information is there to convey that info.
Diffstat (limited to 'cli/i18n/I18nIgnoreFile.php')
-rw-r--r--cli/i18n/I18nIgnoreFile.php63
1 files changed, 0 insertions, 63 deletions
diff --git a/cli/i18n/I18nIgnoreFile.php b/cli/i18n/I18nIgnoreFile.php
deleted file mode 100644
index a05a3d5e8..000000000
--- a/cli/i18n/I18nIgnoreFile.php
+++ /dev/null
@@ -1,63 +0,0 @@
-<?php
-
-require_once __DIR__ . '/I18nFileInterface.php';
-
-class I18nIgnoreFile implements I18nFileInterface {
-
- private $i18nPath;
-
- public function __construct() {
- $this->i18nPath = __DIR__ . '/ignore';
- }
-
- public function dump(array $i18n) {
- foreach ($i18n as $language => $content) {
- $filename = $this->i18nPath . DIRECTORY_SEPARATOR . $language . '.php';
- file_put_contents($filename, $this->format($content));
- }
- }
-
- public function load() {
- $i18n = array();
- $files = new DirectoryIterator($this->i18nPath);
- foreach ($files as $file) {
- if (!$file->isFile()) {
- continue;
- }
- $i18n[$file->getBasename('.php')] = (include $file->getPathname());
- }
-
- return $i18n;
- }
-
- /**
- * 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(($translation), true);
- $patterns = array(
- '/array \(/',
- '/=>\s*array/',
- '/ {2}/',
- '/\d+ => /',
- );
- $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);
- }
-
-}