From 3fbe53d4c6fddae57379ddeb3969b4c9701316a0 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Wed, 6 May 2020 19:58:57 +0200 Subject: [PATCH] Replace generate_ldapsaisie.pot.sh script by a LScli command --- src/includes/class/class.LSlang.php | 89 ++++++++++++++++++ src/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.mo | Bin 56542 -> 56542 bytes src/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.po | 6 +- src/lang/generate_ldapsaisie.pot.sh | 25 ----- src/lang/ldapsaisie.pot | 17 +--- 5 files changed, 94 insertions(+), 43 deletions(-) delete mode 100755 src/lang/generate_ldapsaisie.pot.sh diff --git a/src/includes/class/class.LSlang.php b/src/includes/class/class.LSlang.php index 08d4260b..15bbeae6 100644 --- a/src/includes/class/class.LSlang.php +++ b/src/includes/class/class.LSlang.php @@ -850,3 +850,92 @@ LScli :: add_command( ), false // This command does not need LDAP connection ); + +/** + * CLI generate_ldapsaisie_pot command + * + * @param[in] $command_args array Command arguments + * + * @retval boolean True on succes, false otherwise + **/ +function cli_generate_ldapsaisie_pot($command_args) { + // Clean php file in tmp directory + if (is_dir(LS_TMP_DIR_PATH)) { + foreach(listFiles(LS_TMP_DIR_PATH, '/\.php$/') as $file) { + $tmp_file = LS_TMP_DIR_PATH.$file; + LSlog :: debug("Remove temporary file '$tmp_file'"); + if (!unlink($tmp_file)) { + LSlog :: fatal("Fail to delete temporary file '$tmp_file'."); + } + } + } + + // List PHP files to parse + $php_files = LScli :: run_external_command( + array('find', escapeshellarg(LS_ROOT_DIR), '-name', "'*.php'"), + null, // no STDIN data + false // do not escape command args (already done) + ); + if (!is_array($php_files) || $php_files[0] != 0) { + LSlog :: fatal("Fail to list PHP files."); + } + + // Extract messages from LdapSaisie PHP files using xgettext + $result = LScli :: run_external_command( + array( + "xgettext", + "--from-code utf-8", + "--language=PHP", + "-o", LS_I18N_DIR_PATH."/ldapsaisie-main.pot", // Output + "--omit-header", // No POT header + "--keyword=__", // Handle custom __() translation function + "--keyword=___,", // Handle custom ___() translation function + "--files=-" // Read files to parse from STDIN + ), + $php_files[1] // Pass PHP files list via STDIN + ); + if (!is_array($result) || $result[0] != 0) + LSlog :: fatal("Fail to extract messages from PHP files using xgettext."); + + + // Extract other messages from LdapSaisie templates files + $result = LScli :: run_command( + 'generate_lang_file', + array ( + "-o", LS_I18N_DIR_PATH."/ldapsaisie-templates.pot", + "-f", "pot", + "--only", "templates", + ), + false // do not exit + ); + if (!$result) + LSlog :: fatal("Fail to extract messages from template files using generate_lang_file command."); + + // Merge previous results in ldapsaisie.pot file using msgcat + $result = LScli :: run_external_command(array( + 'msgcat', + LS_I18N_DIR_PATH."/ldapsaisie-main.pot", + LS_I18N_DIR_PATH."/ldapsaisie-templates.pot", + "-o", LS_I18N_DIR_PATH."/ldapsaisie.pot", + )); + if (!is_array($result) || $result[0] != 0) + LSlog :: fatal("Fail to merge messages using msgcat."); + + return true; +} +LScli :: add_command( + 'generate_ldapsaisie_pot', + 'cli_generate_ldapsaisie_pot', + 'Generate ldapsaisie.pot files :', + null, + array( + "This command generate 3 POT files:", + " - ".LS_I18N_DIR_PATH."/ldapsaisie-main.pot", + " => contains messages from PHP files", + " - ".LS_I18N_DIR_PATH."/ldapsaisie-templates.pot", + " => contains messages from templates files", + " - ".LS_I18N_DIR_PATH."/ldapsaisie.pot", + " => contains all messages", + ), + false // This command does not need LDAP connection +); diff --git a/src/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.mo b/src/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.mo index 8ae41612a3499c7552fbf0503a8fff347379682e..db0a5a0c21fea38427fc7670cff12931b3231b75 100644 GIT binary patch delta 19 acmcb&llk6G<_%HhES6TL=9}Zn8&UyRUkC;O delta 19 acmcb&llk6G<_%HhEEZPAMw{cx8&UyRDhK`m diff --git a/src/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.po b/src/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.po index 42fd6bf8..059594e3 100644 --- a/src/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.po +++ b/src/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: LdapSaisie\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2020-05-06 18:32+0200\n" +"PO-Revision-Date: 2020-05-06 19:57+0200\n" "Last-Translator: Benjamin Renard \n" "Language-Team: LdapSaisie \n" @@ -2015,11 +2015,11 @@ msgstr "" "Note: Les paramètres/arguments de la commande doivent être placés après " "celle-ci." -#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LScli.php:251 +#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LScli.php:289 msgid "LScli : The CLI command '%{command}' already exists." msgstr "LScli : La commande CLI '%{command}' existe déjà." -#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LScli.php:254 +#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LScli.php:292 msgid "LScli : The CLI command '%{command}' handler is not callable." msgstr "" "LScli : La fonction de prise en charge de la commande CLI '%{command}' n'est " diff --git a/src/lang/generate_ldapsaisie.pot.sh b/src/lang/generate_ldapsaisie.pot.sh deleted file mode 100755 index e5fa299b..00000000 --- a/src/lang/generate_ldapsaisie.pot.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -# Detect -SRC=$( realpath $( dirname $0 )/../ ) - -# Clean php file in tmp directory -[ -d "$SRC/tmp" ] && rm -fr "$SRC/tmp/*.php" - -# Extract messages from LdapSaisie PHP files using xgettext -xgettext --from-code utf-8 \ - -o "$SRC/lang/ldapsaisie-main.pot" \ - --omit-header \ - --copyright-holder="Easter-eggs" \ - --keyword="__" \ - --keyword="___" \ - $( find "$SRC" -name "*.php" ) - -# Extract other messages from LdapSaisie templates files -$SRC/bin/ldapsaisie.php generate_lang_file \ - -o "$SRC/lang/ldapsaisie-templates.pot" \ - -f pot \ - --only templates - -# Merge previous results in ldapsaisie.pot file -msgcat $SRC/lang/ldapsaisie-main.pot $SRC/lang/ldapsaisie-templates.pot -o $SRC/lang/ldapsaisie.pot diff --git a/src/lang/ldapsaisie.pot b/src/lang/ldapsaisie.pot index 7c654424..f51d2f64 100644 --- a/src/lang/ldapsaisie.pot +++ b/src/lang/ldapsaisie.pot @@ -1,16 +1,3 @@ -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: \n" -"POT-Creation-Date: \n" -"PO-Revision-Date: \n" -"Last-Translator: \n" -"Language-Team: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"X-Generator: Poedit 2.2.1\n" - #: /home/brenard/dev/ldapsaisie_clean3/src/includes/addons/LSaddons.samba.php:27 msgid "SAMBA Support : Unable to load smbHash class." msgstr "" @@ -1720,11 +1707,11 @@ msgid "" "Note: Command's parameter/argument must be place after the command." msgstr "" -#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LScli.php:251 +#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LScli.php:289 msgid "LScli : The CLI command '%{command}' already exists." msgstr "" -#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LScli.php:254 +#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LScli.php:292 msgid "LScli : The CLI command '%{command}' handler is not callable." msgstr ""