Replace generate_ldapsaisie.pot.sh script by a LScli command

This commit is contained in:
Benjamin Renard 2020-05-06 19:58:57 +02:00
parent 1cb2c47bfb
commit 3fbe53d4c6
5 changed files with 94 additions and 43 deletions

View file

@ -850,3 +850,92 @@ LScli :: add_command(
), ),
false // This command does not need LDAP connection 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
);

View file

@ -8,7 +8,7 @@ msgstr ""
"Project-Id-Version: LdapSaisie\n" "Project-Id-Version: LdapSaisie\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: \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 <brenard@zionetrix.net>\n" "Last-Translator: Benjamin Renard <brenard@zionetrix.net>\n"
"Language-Team: LdapSaisie <ldapsaisie-users@lists.labs.libre-entreprise." "Language-Team: LdapSaisie <ldapsaisie-users@lists.labs.libre-entreprise."
"org>\n" "org>\n"
@ -2015,11 +2015,11 @@ msgstr ""
"Note: Les paramètres/arguments de la commande doivent être placés après " "Note: Les paramètres/arguments de la commande doivent être placés après "
"celle-ci." "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." msgid "LScli : The CLI command '%{command}' already exists."
msgstr "LScli : La commande CLI '%{command}' existe déjà." 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." msgid "LScli : The CLI command '%{command}' handler is not callable."
msgstr "" msgstr ""
"LScli : La fonction de prise en charge de la commande CLI '%{command}' n'est " "LScli : La fonction de prise en charge de la commande CLI '%{command}' n'est "

View file

@ -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

View file

@ -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 #: /home/brenard/dev/ldapsaisie_clean3/src/includes/addons/LSaddons.samba.php:27
msgid "SAMBA Support : Unable to load smbHash class." msgid "SAMBA Support : Unable to load smbHash class."
msgstr "" msgstr ""
@ -1720,11 +1707,11 @@ msgid ""
"Note: Command's parameter/argument must be place after the command." "Note: Command's parameter/argument must be place after the command."
msgstr "" 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." msgid "LScli : The CLI command '%{command}' already exists."
msgstr "" 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." msgid "LScli : The CLI command '%{command}' handler is not callable."
msgstr "" msgstr ""