Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
3883ce2
Merge branch 'fix/hide-or-separator-minicart' into release/2.5.2
alexiglesias31 Jan 19, 2024
ae4288d
Merge branch 'fix/error-when-switch-to-paypal' into release/2.5.2
alexiglesias31 Jan 19, 2024
743fbbb
Merge branch 'fix/remove-hide-checkout-button-setting' into release/2…
alexiglesias31 Jan 19, 2024
805e626
Merge branch 'fix/add-compatibility-product-add-on-gravity-add-on' in…
alexiglesias31 Jan 19, 2024
9abf328
Merge branch 'update/composer-polyfills' into release/2.5.2
alexiglesias31 Jan 19, 2024
ba06f3c
Merge branch 'fix/error-jpy-decimals' into release/2.5.2
alexiglesias31 Jan 19, 2024
733e367
Merge branch 'fix/error-non-standard-decimals' into release/2.5.2
alexiglesias31 Jan 19, 2024
41e5492
bump versions to 2.5.2-rc1
alexiglesias31 Jan 19, 2024
b6deef0
Merge branch 'fix/add-compatibility-product-add-on-gravity-add-on' in…
alexiglesias31 Feb 6, 2024
b6fc38e
bump versions to 2.5.2-rc2
alexiglesias31 Feb 6, 2024
8c2fad8
Merge branch 'fix/add-compatibility-product-add-on-gravity-add-on' in…
alexiglesias31 Feb 15, 2024
1659b35
improve detection japanese region
alexiglesias31 Feb 16, 2024
2fe7042
use "-" instead of "." as fallback
alexiglesias31 Mar 5, 2024
9fde4a7
fix 2nd column
alexiglesias31 Mar 23, 2024
9c0d30f
Merge commit '9fde4a7caeaf1e43f8486f990ab922a49fef380c' into release/…
alexiglesias31 May 7, 2024
cc6e061
Merge branch 'fix/issue-js-translations' into release/2.5.2
alexiglesias31 May 7, 2024
0b9f0a2
bump version to 2.5.2-rc3
alexiglesias31 May 7, 2024
f5b6895
[wip] replace button
alexiglesias31 Jun 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Thumbs.db
.settings*
.vscode
.phpunit.result.cache
woorelease.phar
sftp-config.json
/deploy/
/wc-apidocs/
Expand Down
117 changes: 117 additions & 0 deletions bin/update-pot-file-references.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php
// phpcs:ignoreFile - This is an auxiliary build tool, and not part of the plugin.

/**
* Command line script for updating the file references of JS files in a .pot file.
*/

use phpDocumentor\Reflection\DocBlock\Tags\Var_;

/**
* Get the file name from the command line.
*/
if ( $argc !== 2 ) {
echo "Usage: {$argc} php -f {$argv[0]} file.pot\n";
exit;
}

$pot_filename = $argv[1];

if ( ! is_file( $pot_filename ) ) {
echo "[ERROR] File not found: {$pot_filename}\n";
exit;
}

/**
* Parses a .pot file into an array.
*
* @param string $file_name Pot file name.
* @return array Translation messages
*/
function read_pot_translations( string $file_name ): array {
$fh = fopen( $file_name, 'r' );
$originals = [];
$references = [];
$messages = [];
$have_msgid = false;

while ( ! feof( $fh ) ) {
$line = trim( fgets( $fh ) );
if ( ! $line ) {
$message = implode( "\n", $messages );
$originals[ $message ] = $references;
$references = [];
$messages = [];
$have_msgid = false;
continue;
}

if ( 'msgid' == substr( $line, 0, 5 ) ) {
$have_msgid = true;
}

if ( $have_msgid ) {
$messages[] = $line;
} else {
$references[] = $line;
}
}

fclose( $fh );

$message = implode( "\n", $messages );
$originals[ $message ] = $references;
return $originals;
}

/**
* Add the transpiled file path to the references of the translation messages.
*
* @param array $translations POT translations (including references/comments).
* @return array Translation messages
*/
function add_transpiled_filepath_reference_to_comments( array $translations ): array {
foreach ( $translations as $message => $references ) {
// Check references for js/jsx/ts/tsx files
$dist_js_to_add = [];
foreach ( $references as $i => $ref ) {
if ( preg_match( '%^#: (build.+)(\.(js|jsx|ts|tsx)):\d+$%', $ref, $m ) ) {
if ( preg_match( '%\.min\.js$%', $m[1] ) ) {
unset( $translations[ $message ][ $i ] );
continue;
}
if ( empty( $m[2] ) ) {
continue;
}
$dist_js_to_add[] = "#: {$m[1]}.min{$m[2]}:1";
}
}

// Add the new file references to the top of the list.
if ( ! empty( $dist_js_to_add ) ) {
array_splice( $translations[ $message], 0, 0, array_unique( $dist_js_to_add ) );
}
}

return $translations;
}

// Read the translation .pot file.
$translations = read_pot_translations( $pot_filename );

// For transpiled JS client files, we need to add a reference to the generated build file.
$translations = add_transpiled_filepath_reference_to_comments( $translations );

// Delete the original source.
unlink( $pot_filename );

$fh = fopen( $pot_filename, 'w' );

foreach ( $translations as $message => $original ) {
fwrite( $fh, implode( "\n", $original ) );
fwrite( $fh, "\n" . $message . "\n\n" );
}

fclose( $fh );

echo "Updated {$pot_filename}\n";
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"php-stubs/woocommerce-stubs": "^5.1",
"szepeviktor/phpstan-wordpress": "^0.7.5",
"phpstan/extension-installer": "^1.1",
"yoast/phpunit-polyfills": "^1.0"
"yoast/phpunit-polyfills": "^1.0",
"wp-cli/wp-cli-bundle": "*"
},
"require": {
"amzn/amazon-pay-api-sdk-php": "2.6.2",
Expand Down
Loading