Skip to content

Commit 7538d68

Browse files
authored
Merge pull request #389 from wp-cli/fix/make-php-skip-empty
2 parents 46e9483 + e2ca4a6 commit 7538d68

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

features/makephp.feature

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,58 @@ Feature: Generate PHP files from PO files
204204
"""
205205
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']];
206206
"""
207+
208+
Scenario: Excludes strings without translations
209+
Given an empty foo-plugin directory
210+
And a foo-plugin/foo-plugin-de_DE.po file:
211+
"""
212+
# Copyright (C) 2018 Foo Plugin
213+
# This file is distributed under the same license as the Foo Plugin package.
214+
msgid ""
215+
msgstr ""
216+
"Project-Id-Version: Foo Plugin\n"
217+
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/foo-plugin\n"
218+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
219+
"Language-Team: LANGUAGE <[email protected]>\n"
220+
"Language: de_DE\n"
221+
"MIME-Version: 1.0\n"
222+
"Content-Type: text/plain; charset=UTF-8\n"
223+
"Content-Transfer-Encoding: 8bit\n"
224+
"POT-Creation-Date: 2018-05-02T22:06:24+00:00\n"
225+
"PO-Revision-Date: 2018-05-02T22:06:24+00:00\n"
226+
"X-Domain: foo-plugin\n"
227+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
228+
229+
#: foo-plugin.php:10
230+
msgid "I exist"
231+
msgstr "I exist (DE)"
232+
233+
#: foo-plugin.php:20
234+
msgid "I am empty"
235+
msgstr ""
236+
237+
#: foo-plugin.php:30
238+
msgid "You have %d new message"
239+
msgid_plural "You have %d new messages"
240+
msgstr[0] ""
241+
msgstr[1] ""
242+
"""
243+
244+
When I run `wp i18n make-php foo-plugin`
245+
Then STDOUT should contain:
246+
"""
247+
Success: Created 1 file.
248+
"""
249+
And the return code should be 0
250+
And the foo-plugin/foo-plugin-de_DE.l10n.php file should contain:
251+
"""
252+
I exist
253+
"""
254+
And the foo-plugin/foo-plugin-de_DE.l10n.php file should not contain:
255+
"""
256+
I am empty
257+
"""
258+
And the foo-plugin/foo-plugin-de_DE.l10n.php file should not contain:
259+
"""
260+
new message
261+
"""

src/PhpArrayGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected static function toArray( Translations $translations, $include_headers,
7878
* @var Translation $translation
7979
*/
8080
foreach ( $translations as $translation ) {
81-
if ( $translation->isDisabled() ) {
81+
if ( $translation->isDisabled() || ! $translation->hasTranslation() ) {
8282
continue;
8383
}
8484

0 commit comments

Comments
 (0)