mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2024-11-22 01:49:08 +01:00
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:
parent
b3cd453918
commit
bc171e6092
1 changed files with 63 additions and 21 deletions
|
@ -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"));
|
||||
|
||||
|
||||
|
@ -916,7 +916,7 @@ function cli_generate_lang_file($command_args) {
|
|||
LScli :: usage(_("You could specify only one -O/--only parameter."));
|
||||
$only = strtolower($command_args[$i]);
|
||||
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)
|
||||
LScli :: usage(_("You could not use -W/--without parameter combined with -O/--only parameter."));
|
||||
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$$/');
|
||||
}
|
||||
|
||||
// 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
|
||||
ksort($data);
|
||||
|
||||
|
@ -1324,6 +1330,22 @@ ___(
|
|||
**/
|
||||
function cli_generate_ldapsaisie_pot($command_args) {
|
||||
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)
|
||||
if (!isset($LSlang_cli_logger))
|
||||
$LSlang_cli_logger = LSlog :: get_logger('generate_ldapsaisie_pot');
|
||||
|
@ -1351,25 +1373,41 @@ function cli_generate_ldapsaisie_pot($command_args) {
|
|||
return false;
|
||||
}
|
||||
|
||||
// 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
|
||||
true, // Escape parameters
|
||||
LS_ROOT_DIR // Run in LdapSaisie root directory
|
||||
);
|
||||
if (!is_array($result) || $result[0] != 0)
|
||||
$LSlang_cli_logger -> fatal("Fail to extract messages from 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(
|
||||
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
|
||||
true, // Escape parameters
|
||||
LS_ROOT_DIR // Run in LdapSaisie root directory
|
||||
);
|
||||
if (!is_array($result) || $result[0] != 0)
|
||||
$LSlang_cli_logger -> fatal("Fail to extract messages from PHP files using xgettext.");
|
||||
}
|
||||
|
||||
// Extract other messages from LdapSaisie templates files
|
||||
$result = LScli :: run_command(
|
||||
|
@ -1410,6 +1448,10 @@ LScli :: add_command(
|
|||
___(" => contains messages from templates files"),
|
||||
" - ".LS_I18N_DIR_PATH."/ldapsaisie.pot",
|
||||
___(" => 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
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue