From c626bc177a2e6bab488ba3b77ebb50f05c6eee08 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Tue, 28 Feb 2023 01:14:37 +0100 Subject: [PATCH] I18n CLI commands: replace --core parameter by Cli::core_mode() --- src/I18n.php | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/I18n.php b/src/I18n.php index 56aa37d..bb6dd30 100644 --- a/src/I18n.php +++ b/src/I18n.php @@ -319,13 +319,12 @@ class I18n { * @return void */ public static function cli_extract_messages($command_args) { - $core_mode = in_array('--core', $command_args); - $root_path = $core_mode?self::$core_root_path:self::$root_path; + $root_path = Cli::core_mode()?self::$core_root_path:self::$root_path; // Store list of generated POT files $pot_files = array(); - if ($core_mode) { + if (Cli::core_mode()) { // List EesyPHP PHP files to parse $eesyphp_php_files = run_external_command( array( @@ -401,8 +400,8 @@ class I18n { // Extract messages from JS files using xgettext in each registered static directories foreach(Tpl::static_directories() as $idx => $static_directory) { - if ($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; + if (!Cli::core_mode() && $static_directory == Tpl::$core_static_directory) continue; // List JS files to parse $result = run_external_command( array('find', escapeshellarg(basename($static_directory)), '-name', "'*.js'"), @@ -441,8 +440,8 @@ class I18n { if (Tpl :: initialized()) { foreach (Tpl :: templates_directories() as $idx => $templates_directory) { - if ($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; + if (!Cli::core_mode() && $templates_directory == Tpl::$core_templates_directory) continue; // Extract messages from templates files using tsmarty2c.php $result = run_external_command( array( @@ -502,20 +501,17 @@ class I18n { * @return bool */ public static function cli_update_messages($command_args) { - $core_mode = false; $compendium_args = array(); foreach ($command_args as $arg) { - if ($arg == '--core') - $core_mode = true; - else if (!file_exists($arg)) + if (!file_exists($arg)) Log :: fatal(self::_("Compendium file %s not found."), $arg); else { $compendium_args[] = '-C'; $compendium_args[] = $arg; } } - $domain = $core_mode?self::CORE_TEXT_DOMAIN:self::TEXT_DOMAIN; - $root_path = $core_mode?self::$core_root_path:self::$root_path; + $domain = Cli::core_mode()?self::CORE_TEXT_DOMAIN:self::TEXT_DOMAIN; + $root_path = Cli::core_mode()?self::$core_root_path:self::$root_path; $pot_file = "$root_path/messages.pot"; if (!is_file($pot_file)) @@ -595,9 +591,8 @@ class I18n { * @return bool */ public static function cli_compile_messages($command_args) { - $core_mode = in_array('--core', $command_args); - $domain = $core_mode?self::CORE_TEXT_DOMAIN:self::TEXT_DOMAIN; - $root_path = $core_mode?self::$core_root_path:self::$root_path; + $domain = Cli::core_mode()?self::CORE_TEXT_DOMAIN:self::TEXT_DOMAIN; + $root_path = Cli::core_mode()?self::$core_root_path:self::$root_path; if ($dh = opendir($root_path)) { $error = False; while (($file = readdir($dh)) !== false) { @@ -676,7 +671,7 @@ class I18n { } // 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"; if(!$fd = fopen($js_file, 'w')) { Log :: error(self::_("Fail to open %s JS catalog file in write mode (%s)."),