generate_ldapsaisie_pot: Add -I/--internal paramater to use internal message extractor for PHP files instead of xgettext

Note: just for tests, not recommended.
This commit is contained in:
Benjamin Renard 2023-05-26 11:04:01 +02:00
parent b3cd453918
commit bc171e6092
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC

View file

@ -847,7 +847,7 @@ function _cli_output_pot($fd) {
} }
} }
$available_onlys = array("config", "templates", "addons", "auth_methods", "includes"); $available_onlys = array("config", "templates", "addons", "auth_methods", "includes", "php");
$available_withouts = array_merge($available_onlys, array("select-list")); $available_withouts = array_merge($available_onlys, array("select-list"));
@ -916,7 +916,7 @@ function cli_generate_lang_file($command_args) {
LScli :: usage(_("You could specify only one -O/--only parameter.")); LScli :: usage(_("You could specify only one -O/--only parameter."));
$only = strtolower($command_args[$i]); $only = strtolower($command_args[$i]);
if (!in_array($only, $available_onlys)) if (!in_array($only, $available_onlys))
LScli :: usage(_("Invalid -O/--only parameter. Must be one of the following values: %s.'"), implode("','", $available_onlys)); LScli :: usage(_("Invalid -O/--only parameter. Must be one of the following values: '%s'."), implode("', '", $available_onlys));
elseif ($withouts) elseif ($withouts)
LScli :: usage(_("You could not use -W/--without parameter combined with -O/--only parameter.")); LScli :: usage(_("You could not use -W/--without parameter combined with -O/--only parameter."));
break; break;
@ -1179,6 +1179,12 @@ function cli_generate_lang_file($command_args) {
_cli_find_and_parse_php_file(LS_ROOT_DIR.'/'.LS_LOCAL_DIR.LS_CONF_DIR.'/LSauth', '/^config\.(.+)\.php$$/'); _cli_find_and_parse_php_file(LS_ROOT_DIR.'/'.LS_LOCAL_DIR.LS_CONF_DIR.'/LSauth', '/^config\.(.+)\.php$$/');
} }
// Manage all PHP files
if ($only == 'php') {
$LSlang_cli_logger -> info("Looking for string to translate in PHP files");
_cli_find_and_parse_php_file(LS_ROOT_DIR, null, true, array(LS_ROOT_DIR.'/'.LS_LOCAL_DIR));
}
// Sort resulting strings // Sort resulting strings
ksort($data); ksort($data);
@ -1324,6 +1330,22 @@ ___(
**/ **/
function cli_generate_ldapsaisie_pot($command_args) { function cli_generate_ldapsaisie_pot($command_args) {
global $LSlang_cli_logger; global $LSlang_cli_logger;
// Parameters
$use_internal_parser = false;
for ($i=0; $i < count($command_args); $i++) {
switch ($command_args[$i]) {
case '--internal':
case '-I':
$use_internal_parser = true;
break;
default:
LScli :: usage(_("%s: Invalid parameter."), $command_args[$i]);
}
}
// Initialize logger (if not already initialized by another CLI command) // Initialize logger (if not already initialized by another CLI command)
if (!isset($LSlang_cli_logger)) if (!isset($LSlang_cli_logger))
$LSlang_cli_logger = LSlog :: get_logger('generate_ldapsaisie_pot'); $LSlang_cli_logger = LSlog :: get_logger('generate_ldapsaisie_pot');
@ -1351,7 +1373,23 @@ function cli_generate_ldapsaisie_pot($command_args) {
return false; return false;
} }
// Extract messages from LdapSaisie PHP files using xgettext // Extract messages from LdapSaisie PHP files
if ($use_internal_parser) {
// Using internal parser
$result = LScli :: run_command(
'generate_lang_file',
array (
"-o", LS_I18N_DIR_PATH."/ldapsaisie-main.pot",
"-f", "pot",
"--only", "php",
),
false // do not exit
);
if (!$result)
$LSlang_cli_logger -> fatal("Fail to extract messages from PHP files using generate_lang_file command.");
}
else {
// Using xgettext
$result = LScli :: run_external_command( $result = LScli :: run_external_command(
array( array(
"xgettext", "xgettext",
@ -1369,7 +1407,7 @@ function cli_generate_ldapsaisie_pot($command_args) {
); );
if (!is_array($result) || $result[0] != 0) if (!is_array($result) || $result[0] != 0)
$LSlang_cli_logger -> fatal("Fail to extract messages from PHP files using xgettext."); $LSlang_cli_logger -> fatal("Fail to extract messages from PHP files using xgettext.");
}
// Extract other messages from LdapSaisie templates files // Extract other messages from LdapSaisie templates files
$result = LScli :: run_command( $result = LScli :: run_command(
@ -1410,6 +1448,10 @@ LScli :: add_command(
___(" => contains messages from templates files"), ___(" => contains messages from templates files"),
" - ".LS_I18N_DIR_PATH."/ldapsaisie.pot", " - ".LS_I18N_DIR_PATH."/ldapsaisie.pot",
___(" => contains all messages"), ___(" => contains all messages"),
null,
___(
"Note: Use -I / --internal parameter to use internal parser instead of
xgettext for PHP files."),
), ),
false // This command does not need LDAP connection false // This command does not need LDAP connection
); );