Skip to content

Commit

Permalink
Merge pull request #389 from wp-cli/fix/make-php-skip-empty
Browse files Browse the repository at this point in the history
  • Loading branch information
swissspidy authored Feb 28, 2024
2 parents 46e9483 + e2ca4a6 commit 7538d68
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
55 changes: 55 additions & 0 deletions features/makephp.feature
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,58 @@ Feature: Generate PHP files from PO files
"""
return ['domain'=>'foo-plugin','plural-forms'=>'nplurals=2; plural=(n != 1);','language'=>'de_DE','project-id-version'=>'Foo Plugin','pot-creation-date'=>'2018-05-02T22:06:24+00:00','po-revision-date'=>'2018-05-02T22:06:24+00:00','messages'=>['Plugin NameFoo Plugin (EN)'=>'Foo Plugin (DE)','Foo Plugin'=>'Bar Plugin','You have %d new message'=>'Sie haben %d neue Nachricht' . "\0" . 'Sie haben %d neue Nachrichten']];
"""

Scenario: Excludes strings without translations
Given an empty foo-plugin directory
And a foo-plugin/foo-plugin-de_DE.po file:
"""
# Copyright (C) 2018 Foo Plugin
# This file is distributed under the same license as the Foo Plugin package.
msgid ""
msgstr ""
"Project-Id-Version: Foo Plugin\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/foo-plugin\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: de_DE\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2018-05-02T22:06:24+00:00\n"
"PO-Revision-Date: 2018-05-02T22:06:24+00:00\n"
"X-Domain: foo-plugin\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: foo-plugin.php:10
msgid "I exist"
msgstr "I exist (DE)"
#: foo-plugin.php:20
msgid "I am empty"
msgstr ""
#: foo-plugin.php:30
msgid "You have %d new message"
msgid_plural "You have %d new messages"
msgstr[0] ""
msgstr[1] ""
"""

When I run `wp i18n make-php foo-plugin`
Then STDOUT should contain:
"""
Success: Created 1 file.
"""
And the return code should be 0
And the foo-plugin/foo-plugin-de_DE.l10n.php file should contain:
"""
I exist
"""
And the foo-plugin/foo-plugin-de_DE.l10n.php file should not contain:
"""
I am empty
"""
And the foo-plugin/foo-plugin-de_DE.l10n.php file should not contain:
"""
new message
"""
2 changes: 1 addition & 1 deletion src/PhpArrayGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected static function toArray( Translations $translations, $include_headers,
* @var Translation $translation
*/
foreach ( $translations as $translation ) {
if ( $translation->isDisabled() ) {
if ( $translation->isDisabled() || ! $translation->hasTranslation() ) {
continue;
}

Expand Down

0 comments on commit 7538d68

Please sign in to comment.