Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wp i18n make-php command #363

Merged
merged 12 commits into from
Jan 30, 2024
Prev Previous commit
Update file extension
  • Loading branch information
swissspidy committed Jan 16, 2024
commit 28e85d9350d6f9ea10531dcb52365c36d7558c0e
14 changes: 7 additions & 7 deletions features/makephp.feature
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Feature: Generate PHP files from PO files
Success: Created 1 file.
"""
And the return code should be 0
And the foo-plugin/foo-plugin-de_DE.php file should exist
And the foo-plugin/foo-plugin-de_DE.l10n.php file should exist

Scenario: Allows setting custom destination directory
Given an empty foo-plugin directory
Expand Down Expand Up @@ -77,7 +77,7 @@ Feature: Generate PHP files from PO files
Success: Created 1 file.
"""
And the return code should be 0
And the result/foo-plugin-de_DE.php file should exist
And the result/foo-plugin-de_DE.l10n.php file should exist

Scenario: Does include headers
Given an empty foo-plugin directory
Expand Down Expand Up @@ -112,19 +112,19 @@ Feature: Generate PHP files from PO files
"""
And the return code should be 0
And STDERR should be empty
And the foo-plugin/foo-plugin-de_DE.php file should contain:
And the foo-plugin/foo-plugin-de_DE.l10n.php file should contain:
"""
'language'=>'de_DE'
"""
And the foo-plugin/foo-plugin-de_DE.php file should contain:
And the foo-plugin/foo-plugin-de_DE.l10n.php file should contain:
"""
'domain'=>'foo-plugin'
"""
And the foo-plugin/foo-plugin-de_DE.php file should contain:
And the foo-plugin/foo-plugin-de_DE.l10n.php file should contain:
"""
'plural-forms'=>'nplurals=2; plural=(n != 1);'
"""
And the foo-plugin/foo-plugin-de_DE.php file should contain:
And the foo-plugin/foo-plugin-de_DE.l10n.php file should contain:
"""
'messages'=>[''=>['Foo Plugin'=>['Foo Plugin']]]
"""
Expand Down Expand Up @@ -161,7 +161,7 @@ Feature: Generate PHP files from PO files
Success: Created 1 file.
"""
And the return code should be 0
And the foo-plugin/foo-plugin-de_DE.php file should contain:
And the foo-plugin/foo-plugin-de_DE.l10n.php file should contain:
"""
'messages'=>[''=>['Foo Plugin'=>['Bar Plugin']]]
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have a test that verifies a valid PHP translation file is produced?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid as in syntax or as in translation gets loaded properly in WordPress?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking the latter but we could check both, I suppose.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably best done in a future PR because we don't have similar assertions for the other file formats, and the PHP format especially is not yet merged into core.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good 👍

2 changes: 1 addition & 1 deletion src/MakePhpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function __invoke( $args, $assoc_args ) {
}

$file_basename = basename( $file->getFilename(), '.po' );
$destination_file = "{$destination}/{$file_basename}.php";
$destination_file = "{$destination}/{$file_basename}.l10n.php";

$translations = Translations::fromPoFile( $file->getPathname() );
if ( ! PhpArrayGenerator::toFile( $translations, $destination_file ) ) {
Expand Down