diff --git a/inc/core/improve.php b/inc/core/improve.php index 96d8c65..91943b8 100644 --- a/inc/core/improve.php +++ b/inc/core/improve.php @@ -33,7 +33,7 @@ class improve { /** @var array Allowed file extensions to open */ private static $readfile_extensions = [ - 'php', 'xml', 'js', 'css', 'csv', 'html', 'htm', 'txt', 'md', + 'php', 'xml', 'js', 'css', 'csv', 'html', 'htm', 'txt', 'md', 'po', ]; /** @var array $actions Loaded actions modules */ diff --git a/inc/module/po2php.php b/inc/module/po2php.php new file mode 100644 index 0000000..58262f7 --- /dev/null +++ b/inc/module/po2php.php @@ -0,0 +1,75 @@ +setProperties([ + 'id' => 'po2php', + 'name' => __('Translation files'), + 'description' => __('Compile existing translation .po files to fresh .lang.php files'), + 'priority' => 310, + 'types' => ['plugin', 'theme'], + ]); + + return true; + } + + public function isConfigured(): bool + { + return true; + } + + public function closeFile(): ?bool + { + if (!in_array($this->path_extension, ['po'])) { + return null; + } + + if (l10n::generatePhpFileFromPo(substr($this->path_full, 0, -3), $this->license)) { + $this->setSuccess(__('Compile .po file to .lang.php')); + } else { + $this->setError(__('Failed to compile .po file')); + } + + return true; + } +} diff --git a/locales/fr/main.po b/locales/fr/main.po index 192a615..63aa9bd 100644 --- a/locales/fr/main.po +++ b/locales/fr/main.po @@ -3,7 +3,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Project-Id-Version: improve 0.10\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2022-12-03T22:40:15+00:00\n" +"PO-Revision-Date: 2022-12-21T11:10:34+00:00\n" "Last-Translator: Jean-Christian Denis\n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -316,6 +316,18 @@ msgstr "Aucune erreur trouvé" msgid "Failed to run phpstan" msgstr "Impossible d'exécuter PHPStan" +msgid "Translation files" +msgstr "Fichier de traductions" + +msgid "Compile existing translation .po files to fresh .lang.php files" +msgstr "Compile les fichiers de traductions .po existants en fichiers compilés .lang.php" + +msgid "Compile .po file to .lang.php" +msgstr "Fichier .po compilé en .lang.php" + +msgid "Failed to compile .po file" +msgstr "Impossible de compiler le fichier .po" + msgid "Tabulations" msgstr "Tabulations"