Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@
/phpstan.neon.dist export-ignore
/phpunit.xml.dist export-ignore
/tests export-ignore
/stubs export-ignore
/wp-cli.yml export-ignore
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
],
"require": {
"eftec/bladeone": "3.52",
"gettext/gettext": "^4.8",
"gettext/gettext": "^5.7.4",
"gettext/php-scanner": "^2.1",
"mck89/peast": "^1.13.11",
"wp-cli/wp-cli": "^3.0"
},
Expand Down
28 changes: 28 additions & 0 deletions features/makemo.feature
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,31 @@ Feature: Generate MO files from PO files
JS Only Translation
"""


Scenario: Includes translations that are "0"
Given an empty foo-plugin directory
And a foo-plugin/foo-plugin-de_DE.po file:
"""
msgid ""
msgstr ""
"Project-Id-Version: Foo Plugin\n"
"Language: de_DE\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Domain: foo-plugin\n"

#: foo-plugin.php:10
msgctxt "start of week"
msgid "1"
msgstr "0"
"""

When I run `wp i18n make-mo 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.mo file should contain:
"""
start of week
"""
36 changes: 36 additions & 0 deletions features/makephp.feature
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,39 @@ Feature: Generate PHP files from PO files
[,
"""


Scenario: Includes translations that are "0"
Given an empty foo-plugin directory
And a foo-plugin/foo-plugin-de_DE.po file:
"""
msgid ""
msgstr ""
"Project-Id-Version: Foo Plugin\n"
"Language: de_DE\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Domain: foo-plugin\n"

#: foo-plugin.php:10
msgctxt "start of week"
msgid "1"
msgstr "0"

#: foo-plugin.php:20
msgid "0"
msgstr "Null"
"""

When I run `wp i18n make-php foo-plugin --pretty-print`
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:
"""
1' => '0',
"""
And the foo-plugin/foo-plugin-de_DE.l10n.php file should contain:
"""
0 => 'Null',
"""
129 changes: 123 additions & 6 deletions features/makepot.feature
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ Feature: Generate a POT file of a WordPress project
And I run `wp i18n make-pot wp-content/plugins/hello-world wp-content/plugins/hello-world/languages/hello-world.pot`
Then the wp-content/plugins/hello-world/languages/hello-world.pot file should contain:
"""
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"""

Scenario: Sets the generator header
Expand Down Expand Up @@ -1765,17 +1765,23 @@ Feature: Generate a POT file of a WordPress project
# This file is distributed under the same license as the Hello World plugin.
msgid ""
msgstr ""
"Project-Id-Version: Hello World 0.1.0\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/hello-world\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Content-Transfer-Encoding: 8bit\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"""
And the wp-content/plugins/hello-world/languages/hello-world.pot file should contain:
"""
"Project-Id-Version: Hello World 0.1.0\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/hello-world\n"
"""
And the wp-content/plugins/hello-world/languages/hello-world.pot file should not contain:
"""
"POT-Creation-Date: 2018-05-02T22:06:24+00:00\n"
"""
And the wp-content/plugins/hello-world/languages/hello-world.pot file should not contain:
"""
"PO-Revision-Date: 2018-05-02T22:06:24+00:00\n"
"""
And the wp-content/plugins/hello-world/languages/hello-world.pot file should contain:
Expand Down Expand Up @@ -4401,3 +4407,114 @@ Feature: Generate a POT file of a WordPress project
#, js-format
msgid "Buongiorno %1$s"
"""

Scenario: Subtracts and merges strings that are "0"
Given an empty foo-plugin directory
And a foo-plugin/exception.pot file:
"""
msgid ""
msgstr ""
"Project-Id-Version: Foo Plugin\n"

#: other.php:1
msgid "0"
msgstr ""
"""
And a foo-plugin/existing.pot file:
"""
msgid ""
msgstr ""
"Project-Id-Version: Foo Plugin\n"

#: existing.php:1
msgctxt "number"
msgid "0"
msgstr ""
"""
And a foo-plugin/foo-plugin.php file:
"""
<?php
/**
* Plugin Name: Foo Plugin
*/

__( '0', 'foo-plugin' );

__( 'Hello World', 'foo-plugin' );
"""

When I run `wp i18n make-pot foo-plugin foo-plugin/foo-plugin.pot --subtract=foo-plugin/exception.pot --merge=foo-plugin/existing.pot`
Then STDOUT should be:
"""
Plugin file detected.
Success: POT file successfully generated.
"""
And STDERR should be empty
And the foo-plugin/foo-plugin.pot file should contain:
"""
#: existing.php:1
msgctxt "number"
msgid "0"
msgstr ""
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgid "Hello World"
"""
And the foo-plugin/foo-plugin.pot file should not contain:
"""
#: foo-plugin.php:6
"""

Scenario: Groups references by file and sorts flags
Given an empty foo-plugin directory
And a foo-plugin/foo-plugin.php file:
"""
<?php
/**
* Plugin Name: Foo Plugin
*/

/* translators: %s: Name */
__( 'Hello %s', 'foo-plugin' );
"""
And a foo-plugin/admin.php file:
"""
<?php
/* translators: %s: Name */
__( 'Hello %s', 'foo-plugin' );
"""
And a foo-plugin/build/index.js file:
"""
/* translators: %s: Name */
__( 'Hello %s', 'foo-plugin' );
"""
And a foo-plugin/build/index.js.map file:
"""
{"version":3,"sources":["index.js"],"sourcesContent":["\n\n/* translators: %s: Name */\n__( 'Hello %s', 'foo-plugin' );"]}
"""
And a foo-plugin/build/view.js file:
"""
/* translators: %s: Name */
__( 'Hello %s', 'foo-plugin' );
"""

When I run `wp i18n make-pot foo-plugin`
Then STDOUT should be:
"""
Plugin file detected.
Success: POT file successfully generated.
"""
And STDERR should be empty
And the foo-plugin/foo-plugin.pot file should contain:
"""
#. translators: %s: Name
#: admin.php:3
#: foo-plugin.php:7
#: build/index.js:2
#: build/index.js:4
#: build/view.js:2
#, js-format,php-format
msgid "Hello %s"
msgstr ""
"""
Loading