I18n: fix extracting messages from all PHP, JS and templates files

This commit is contained in:
Benjamin Renard 2023-02-13 02:36:40 +01:00
parent 317cb30cb3
commit 5691494f12
10 changed files with 1347 additions and 1060 deletions

View file

@ -21,7 +21,6 @@
"brenard/php-unidecode": "dev-master",
"smarty/smarty": "3.1.34",
"smarty-gettext/smarty-gettext": "^1.6",
"smarty-gettext/tsmarty2c": "^0.2.1",
"sepia/po-parser": "^6.0",
"sentry/sdk": "^3.3",
"ext-pdo": "^7.3",

View file

@ -188,114 +188,127 @@ msgid ""
"directories to MO files and as JSON catalogs in public_html/translations."
msgstr ""
#: I18n.php:277 I18n.php:307
msgid "Fail to list PHP files."
#: I18n.php:277
msgid "Fail to list EesyPHP PHP files."
msgstr ""
#: I18n.php:296 I18n.php:326
#: I18n.php:297
msgid "Fail to extract messages from EesyPHP PHP files using xgettext."
msgstr ""
#: I18n.php:309
msgid "Fail to list application PHP files."
msgstr ""
#: I18n.php:329
msgid "Fail to extract messages from PHP files using xgettext."
msgstr ""
#: I18n.php:338
#: I18n.php:342
#, php-format
msgid "Fail to list JS files in '%s' static directory."
msgid "Fail to list JS files in the directory of static files '%s'."
msgstr ""
#: I18n.php:358
msgid "Fail to extract messages from JS files using xgettext."
msgstr ""
#: I18n.php:374
#: I18n.php:364
#, php-format
msgid ""
"Fail to extract messages from template files using tsmarty2c.php script."
"Fail to extract messages from JS files in the directory of static files '%s' "
"using xgettext."
msgstr ""
#: I18n.php:402
#: I18n.php:384
#, php-format
msgid ""
"Fail to extract messages from templates directory '%s' using tsmarty2c.php "
"script."
msgstr ""
#: I18n.php:420
msgid "Fail to merge messages using msgcat."
msgstr ""
#: I18n.php:416
#: I18n.php:434
#, php-format
msgid "Compendium file %s not found."
msgstr ""
#: I18n.php:423
#: I18n.php:441
#, php-format
msgid "POT file not found (%s). Please run extract_messages first."
msgstr ""
#: I18n.php:435 I18n.php:543
#: I18n.php:453 I18n.php:561
#, php-format
msgid "Lang directory '%s' found"
msgstr ""
#: I18n.php:441 I18n.php:549
#: I18n.php:459 I18n.php:567
#, php-format
msgid "LC_MESSAGES directory not found in lang '%s' directory, ignore it."
msgstr ""
#: I18n.php:456
#: I18n.php:474
#, php-format
msgid "Fail to init messages in %s PO file using msginit (%s)."
msgstr ""
#: I18n.php:474
#: I18n.php:492
#, php-format
msgid "Fail to update messages in %s PO file using msgmerge (%s)."
msgstr ""
#: I18n.php:480 I18n.php:557
#: I18n.php:498 I18n.php:575
#, php-format
msgid "PO file not found in lang '%s' directory, ignore it."
msgstr ""
#: I18n.php:487 I18n.php:597
#: I18n.php:505 I18n.php:615
#, php-format
msgid "Fail to open root lang directory (%s)."
msgstr ""
#: I18n.php:513
#: I18n.php:531
#, php-format
msgid "Lang alias symlink found: %s -> %s"
msgstr ""
#: I18n.php:520
#: I18n.php:538
#, php-format
msgid "JSON catalog symlink for %s -> %s created (%s)"
msgstr ""
#: I18n.php:524
#: I18n.php:542
#, php-format
msgid "Fail to create JSON catalog symlink for %s -> %s (%s)"
msgstr ""
#: I18n.php:530
#: I18n.php:548
#, php-format
msgid "JSON catalog symlink for %s -> %s already exist (%s)"
msgstr ""
#: I18n.php:535
#: I18n.php:553
#, php-format
msgid ""
"JSON catalog file for %s already exist, but it's not a symlink to %s (%s)"
msgstr ""
#: I18n.php:570
#: I18n.php:588
#, php-format
msgid "Fail to compile messages from %s PO file as MO file using msgfmt (%s)."
msgstr ""
#: I18n.php:580
#: I18n.php:598
#, php-format
msgid "Fail to open %s JSON catalog file in write mode (%s)."
msgstr ""
#: I18n.php:585
#: I18n.php:603
#, php-format
msgid "Fail to write %s JSON catalog in file (%s)."
msgstr ""
#: I18n.php:590
#: I18n.php:608
#, php-format
msgid "%s JSON catalog writed (%s)."
msgstr ""

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,7 @@
msgid ""
msgstr ""
"POT-Creation-Date: 2022-04-25 18:40+0200\n"
"PO-Revision-Date: 2022-04-25 18:40+0200\n"
"POT-Creation-Date: 2023-02-13 02:32+0100\n"
"PO-Revision-Date: 2023-02-13 02:32+0100\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"

View file

@ -0,0 +1,44 @@
#: static/js/myconfirm.js:4 static/js/myconfirm.js:171
#: static/js/myconfirm.js:200
msgid "Confirmation"
msgstr ""
#: static/js/myconfirm.js:5
msgid "Do you confirm?"
msgstr ""
#: static/js/myconfirm.js:11 static/js/myconfirm.js:108
msgid "Cancel"
msgstr ""
#: static/js/myconfirm.js:17 static/js/myconfirm.js:114
msgid "Validate"
msgstr ""
#: static/js/myconfirm.js:44
msgid "Error"
msgstr ""
#: static/js/myconfirm.js:52
msgid "OK"
msgstr ""
#: static/js/myconfirm.js:91
msgid "Question"
msgstr ""
#: static/js/myconfirm.js:92
msgid "Please enter your answer below:"
msgstr ""
#: static/js/myconfirm.js:143
msgid "Please wait"
msgstr ""
#: static/js/myconfirm.js:144
msgid "Please wait while your request is being processed."
msgstr ""
#: static/js/myconfirm.js:172 static/js/myconfirm.js:201
msgid "Are you sure?"
msgstr ""

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,110 @@
msgid ""
msgstr "Content-Type: text/plain; charset=UTF-8\n"
#: templates/show.tpl:5 templates/search.tpl:36 templates/form.tpl:7
msgid "Name"
msgstr ""
#: templates/show.tpl:14
msgid "Creation date"
msgstr ""
#: templates/show.tpl:23 templates/search.tpl:11 templates/form.tpl:15
msgid "Status"
msgstr ""
#: templates/show.tpl:32 templates/form.tpl:25
msgid "Description"
msgstr ""
#: templates/show.tpl:35
msgid "Unspecified."
msgstr ""
#: templates/show.tpl:42 templates/form.tpl:33
msgid "Back"
msgstr ""
#: templates/show.tpl:43 templates/search.tpl:51
msgid "Modify"
msgstr ""
#: templates/show.tpl:44 templates/search.tpl:52
msgid "Are you sure you want to archive this item?"
msgstr ""
#: templates/show.tpl:44 templates/search.tpl:52
msgid "Archive"
msgstr ""
#: templates/show.tpl:45 templates/search.tpl:53
msgid "Are you sure you want to delete this item?"
msgstr ""
#: templates/show.tpl:45 templates/search.tpl:53
msgid "Delete"
msgstr ""
#: templates/search.tpl:8
msgid "Pattern"
msgstr ""
#: templates/search.tpl:16
msgid "Nb by page"
msgstr ""
#: templates/search.tpl:22
msgid "Search"
msgstr ""
#: templates/search.tpl:23
msgid "Reset"
msgstr ""
#: templates/search.tpl:28 templates/form.tpl:38
msgid "Add"
msgstr ""
#: templates/search.tpl:35
msgid "Date"
msgstr ""
#: templates/search.tpl:37
msgid "Actions"
msgstr ""
#: templates/search.tpl:47 templates/search.tpl:50
msgid "View"
msgstr ""
#: templates/search.tpl:59
msgid "No item found."
msgstr ""
#: templates/search.tpl:68
msgid "%3 element"
msgid_plural "Elements %1 to %2 on %3"
msgstr[0] ""
msgstr[1] ""
#: templates/homepage.tpl:5
msgid "Hello, world!"
msgstr ""
#: templates/homepage.tpl:6
msgid ""
"This is a simple app to show the different possibilities and basic "
"functionality."
msgstr ""
#: templates/homepage.tpl:8
msgid "This app contains some demo pages:"
msgstr ""
#: templates/homepage.tpl:9
msgid "Search page"
msgstr ""
#: templates/form.tpl:36
msgid "Save"
msgstr ""

View file

@ -0,0 +1,28 @@
msgid ""
msgstr "Content-Type: text/plain; charset=UTF-8\n"
#: templates/fatal_error.tpl:5
msgid ""
"A fatal error has occurred and it is preventing this application from "
"working properly. Please try again later or contact support."
msgstr ""
#: templates/fatal_error.tpl:7
msgid "Error: %1"
msgstr ""
#: templates/fatal_error.tpl:9
msgid "Back"
msgstr ""
#: templates/homepage.tpl:5
msgid "Hello, world!"
msgstr ""
#: templates/homepage.tpl:6
msgid ""
"This is the default page of a new app using EesyPHP framework. Register your "
"own templates directory and create a <em>homepage.tpl</em> file to overwrite "
"it. You could also overwrite the URL handler for the root of the web "
"application."
msgstr ""

View file

@ -274,29 +274,31 @@ class I18n {
__DIR__ // Run from EesyPHP src directory
);
if (!is_array($eesyphp_php_files) || $eesyphp_php_files[0] != 0) {
Log :: fatal(_("Fail to list PHP files."));
Log :: fatal(_("Fail to list EesyPHP PHP files."));
}
// Extract messages from EesyPHP PHP files using xgettext
$pot_file = self :: $root_path."/eesyphp-messages.pot";
$result = run_external_command(
array(
"xgettext",
"--from-code utf-8",
"--language=PHP",
"-o", self :: $root_path."/eesyphp-messages.pot", // Output
"--omit-header", // No POT header
"--keyword=___", // Handle custom ___() translation function
"--files=-" // Read files to parse from STDIN
"-o", $pot_file, // Output
"--omit-header", // No POT header
"--keyword=___", // Handle custom ___() translation function
"--files=-" // Read files to parse from STDIN
),
$eesyphp_php_files[1], // Pass PHP files list via STDIN
true, // Escape parameters
__DIR__ // Run from EesyPHP src directory
$eesyphp_php_files[1], // Pass PHP files list via STDIN
true, // Escape parameters
__DIR__ // Run from EesyPHP src directory
);
if (!is_array($result) || $result[0] != 0)
Log :: fatal(_("Fail to extract messages from PHP files using xgettext."));
$pot_files[] = self :: $root_path."/eesyphp-messages.pot";
Log :: fatal(_("Fail to extract messages from EesyPHP PHP files using xgettext."));
if (is_file($pot_file))
$pot_files[] = $pot_file;
// List PHP files to parse
// List application PHP files to parse
$php_files = run_external_command(
array('find', '-name', "'*.php'"),
null, // no STDIN data
@ -304,75 +306,91 @@ class I18n {
App :: root_directory_path() // Run from Application root directory
);
if (!is_array($php_files) || $php_files[0] != 0) {
Log :: fatal(_("Fail to list PHP files."));
Log :: fatal(_("Fail to list application PHP files."));
}
// Extract messages from PHP files using xgettext
$pot_file = self :: $root_path."/php-messages.pot";
$result = run_external_command(
array(
"xgettext",
"--from-code utf-8",
"--language=PHP",
"-o", self :: $root_path."/php-messages.pot", // Output
"--omit-header", // No POT header
"--keyword=___", // Handle custom ___() translation function
"--files=-" // Read files to parse from STDIN
"-o", $pot_file, // Output
"--omit-header", // No POT header
"--keyword=___", // Handle custom ___() translation function
"--files=-" // Read files to parse from STDIN
),
$php_files[1], // Pass PHP files list via STDIN
true, // Escape parameters
App :: root_directory_path() // Run from EesyPHP src directory
$php_files[1], // Pass PHP files list via STDIN
true, // Escape parameters
App :: root_directory_path() // Run from EesyPHP src directory
);
if (!is_array($result) || $result[0] != 0)
Log :: fatal(_("Fail to extract messages from PHP files using xgettext."));
$pot_files[] = self :: $root_path."/php-messages.pot";
// List JS files to parse
$js_files = array();
foreach(Tpl::static_directories() as $static_directory) {
// Extract messages from JS files using xgettext in each registered static directories
foreach(Tpl::static_directories() as $idx => $static_directory) {
// List JS files to parse
$result = run_external_command(
array('find', escapeshellarg($static_directory), '-name', "'*.js'"),
array('find', escapeshellarg(basename($static_directory)), '-name', "'*.js'"),
null, // no STDIN data
false // do not escape command args (already done)
false, // do not escape command args (already done)
dirname($static_directory) // Run from parent directory
);
if (!is_array($result) || $result[0] != 0) {
Log :: fatal(_("Fail to list JS files in '%s' static directory."), $static_directory);
Log :: fatal(_("Fail to list JS files in the directory of static files '%s'."), $static_directory);
return;
}
$js_files[] = $result[1];
}
// Extract messages from JS files using xgettext
$result = run_external_command(
array(
"xgettext",
"--from-code utf-8",
"--language=JavaScript",
"-o", self :: $root_path."/js-messages.pot", // Output
"--omit-header", // No POT header
"--keyword=___", // Handle custom ___() translation function
"--files=-" // Read files to parse from STDIN
),
implode("\n", $js_files) // Pass JS files list via STDIN
);
if (!is_array($result) || $result[0] != 0)
Log :: fatal(_("Fail to extract messages from JS files using xgettext."));
$pot_files[] = self :: $root_path."/js-messages.pot";
if (Tpl :: initialized()) {
// Extract messages from templates files using tsmarty2c.php
// Extract messages from JS files using xgettext
$pot_file = self :: $root_path."/js-$idx-messages.pot";
$result = run_external_command(
array_merge(
array(
App :: root_directory_path()."/vendor/bin/tsmarty2c.php",
"-o", self :: $root_path."/templates-messages.pot",
),
Tpl :: templates_directories(),
)
array(
"xgettext",
"--from-code utf-8",
"--language=JavaScript",
"-o", $pot_file, // Output
"--omit-header", // No POT header
"--keyword=___", // Handle custom ___() translation function
"--files=-" // Read files to parse from STDIN
),
$result[1], // Pass JS files list via STDIN
true, // Escape arguments
dirname($static_directory) // Run from parent directory
);
if (!is_array($result) || $result[0] != 0)
Log :: fatal(
_("Fail to extract messages from template files using tsmarty2c.php script."));
$pot_files[] = self :: $root_path."/templates-messages.pot";
_("Fail to extract messages from JS files in the directory of static files '%s' using xgettext."),
$static_directory);
if (is_file($pot_file))
$pot_files[] = $pot_file;
}
if (Tpl :: initialized()) {
foreach (Tpl :: templates_directories() as $idx => $templates_directory) {
// Extract messages from templates files using tsmarty2c.php
$result = run_external_command(
array(
App :: root_directory_path()."/vendor/smarty-gettext/smarty-gettext/tsmarty2c.php",
basename($templates_directory),
),
null, // Pass nothing on STDIN
true, // Escape arguments
dirname($templates_directory) // Run from parent directory
);
if (!is_array($result) || $result[0] != 0)
Log :: fatal(
_("Fail to extract messages from templates directory '%s' using tsmarty2c.php script."),
$templates_directory
);
if (!$result[1]) continue;
$pot_file = self :: $root_path."/templates-$idx-messages.pot";
$fd = fopen($pot_file, 'w');
fwrite($fd, $result[1]);
fclose($fd);
$pot_files[] = $pot_file;
}
}
$fd = fopen(self :: $root_path."/headers.pot", 'w');