I18n CLI commands: replace --core parameter by Cli::core_mode()

This commit is contained in:
Benjamin Renard 2023-02-28 01:14:37 +01:00
parent f499087241
commit c626bc177a

View file

@ -319,13 +319,12 @@ class I18n {
* @return void * @return void
*/ */
public static function cli_extract_messages($command_args) { public static function cli_extract_messages($command_args) {
$core_mode = in_array('--core', $command_args); $root_path = Cli::core_mode()?self::$core_root_path:self::$root_path;
$root_path = $core_mode?self::$core_root_path:self::$root_path;
// Store list of generated POT files // Store list of generated POT files
$pot_files = array(); $pot_files = array();
if ($core_mode) { if (Cli::core_mode()) {
// List EesyPHP PHP files to parse // List EesyPHP PHP files to parse
$eesyphp_php_files = run_external_command( $eesyphp_php_files = run_external_command(
array( array(
@ -401,8 +400,8 @@ class I18n {
// Extract messages from JS files using xgettext in each registered static directories // Extract messages from JS files using xgettext in each registered static directories
foreach(Tpl::static_directories() as $idx => $static_directory) { foreach(Tpl::static_directories() as $idx => $static_directory) {
if ($core_mode && $static_directory != Tpl::$core_static_directory) continue; if (Cli::core_mode() && $static_directory != Tpl::$core_static_directory) continue;
if (!$core_mode && $static_directory == Tpl::$core_static_directory) continue; if (!Cli::core_mode() && $static_directory == Tpl::$core_static_directory) continue;
// List JS files to parse // List JS files to parse
$result = run_external_command( $result = run_external_command(
array('find', escapeshellarg(basename($static_directory)), '-name', "'*.js'"), array('find', escapeshellarg(basename($static_directory)), '-name', "'*.js'"),
@ -441,8 +440,8 @@ class I18n {
if (Tpl :: initialized()) { if (Tpl :: initialized()) {
foreach (Tpl :: templates_directories() as $idx => $templates_directory) { foreach (Tpl :: templates_directories() as $idx => $templates_directory) {
if ($core_mode && $templates_directory != Tpl::$core_templates_directory) continue; if (Cli::core_mode() && $templates_directory != Tpl::$core_templates_directory) continue;
if (!$core_mode && $templates_directory == Tpl::$core_templates_directory) continue; if (!Cli::core_mode() && $templates_directory == Tpl::$core_templates_directory) continue;
// Extract messages from templates files using tsmarty2c.php // Extract messages from templates files using tsmarty2c.php
$result = run_external_command( $result = run_external_command(
array( array(
@ -502,20 +501,17 @@ class I18n {
* @return bool * @return bool
*/ */
public static function cli_update_messages($command_args) { public static function cli_update_messages($command_args) {
$core_mode = false;
$compendium_args = array(); $compendium_args = array();
foreach ($command_args as $arg) { foreach ($command_args as $arg) {
if ($arg == '--core') if (!file_exists($arg))
$core_mode = true;
else if (!file_exists($arg))
Log :: fatal(self::_("Compendium file %s not found."), $arg); Log :: fatal(self::_("Compendium file %s not found."), $arg);
else { else {
$compendium_args[] = '-C'; $compendium_args[] = '-C';
$compendium_args[] = $arg; $compendium_args[] = $arg;
} }
} }
$domain = $core_mode?self::CORE_TEXT_DOMAIN:self::TEXT_DOMAIN; $domain = Cli::core_mode()?self::CORE_TEXT_DOMAIN:self::TEXT_DOMAIN;
$root_path = $core_mode?self::$core_root_path:self::$root_path; $root_path = Cli::core_mode()?self::$core_root_path:self::$root_path;
$pot_file = "$root_path/messages.pot"; $pot_file = "$root_path/messages.pot";
if (!is_file($pot_file)) if (!is_file($pot_file))
@ -595,9 +591,8 @@ class I18n {
* @return bool * @return bool
*/ */
public static function cli_compile_messages($command_args) { public static function cli_compile_messages($command_args) {
$core_mode = in_array('--core', $command_args); $domain = Cli::core_mode()?self::CORE_TEXT_DOMAIN:self::TEXT_DOMAIN;
$domain = $core_mode?self::CORE_TEXT_DOMAIN:self::TEXT_DOMAIN; $root_path = Cli::core_mode()?self::$core_root_path:self::$root_path;
$root_path = $core_mode?self::$core_root_path:self::$root_path;
if ($dh = opendir($root_path)) { if ($dh = opendir($root_path)) {
$error = False; $error = False;
while (($file = readdir($dh)) !== false) { while (($file = readdir($dh)) !== false) {
@ -676,7 +671,7 @@ class I18n {
} }
// Compile messages from PO file to JS catalog file // Compile messages from PO file to JS catalog file
$js_catalog = self :: po2json($lang, $po_file, $core_mode); $js_catalog = self :: po2json($lang, $po_file, Cli::core_mode());
$js_file = "$root_path/$lang.js"; $js_file = "$root_path/$lang.js";
if(!$fd = fopen($js_file, 'w')) { if(!$fd = fopen($js_file, 'w')) {
Log :: error(self::_("Fail to open %s JS catalog file in write mode (%s)."), Log :: error(self::_("Fail to open %s JS catalog file in write mode (%s)."),