Skip to content
Open
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"require": {
"eftec/bladeone": "3.52",
"gettext/gettext": "^4.8",
"gettext/gettext": "^5.7",
"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 <LL@li.org>\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 <LL@li.org>\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 ""
"""
125 changes: 125 additions & 0 deletions features/updatepo.feature
Original file line number Diff line number Diff line change
Expand Up @@ -864,3 +864,128 @@ Feature: Update existing PO files from a POT file
Success: Updated 1 file. 1 file unchanged.
"""
And STDERR should be empty

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

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

#: foo-plugin.php:2
msgid "0"
msgstr ""

#: foo-plugin.php:3
msgid "%d item"
msgid_plural "%d items"
msgstr[0] ""
msgstr[1] ""
"""
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:30
msgid "%d item"
msgid_plural "%d items"
msgstr[0] "0"
msgstr[1] "0"
"""

When I run `wp i18n update-po foo-plugin/foo-plugin.pot`
Then STDOUT should be:
"""
Success: Updated 1 file.
"""
And STDERR should be empty
And the foo-plugin/foo-plugin-de_DE.po file should contain:
"""
#: foo-plugin.php:1
msgctxt "start of week"
msgid "1"
msgstr "0"

#: foo-plugin.php:2
msgid "0"
msgstr ""

#: foo-plugin.php:3
msgid "%d item"
msgid_plural "%d items"
msgstr[0] "0"
msgstr[1] "0"
"""

Scenario: Sorts headers and flags and groups references by file
Given an empty foo-plugin directory
And a foo-plugin/foo-plugin.pot file:
"""
msgid ""
msgstr ""
"Project-Id-Version: Foo Plugin\n"
"X-Domain: foo-plugin\n"

#: foo-plugin.php:20
#: build/index.js:1
#: foo-plugin.php:10
#, php-format,js-format
msgid "Hello %s"
msgstr ""
"""
And a foo-plugin/foo-plugin-de_DE.po file:
"""
msgid ""
msgstr ""
"Project-Id-Version: Foo Plugin\n"
"Language: de_DE\n"
"X-Poedit-Basepath: ..\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 3.0\n"
"X-Domain: foo-plugin\n"

#: foo-plugin.php:1
#, php-format,fuzzy
msgid "Hello %s"
msgstr "Hallo %s"
"""

When I run `wp i18n update-po foo-plugin/foo-plugin.pot`
Then STDOUT should be:
"""
Success: Updated 1 file.
"""
And STDERR should be empty
And the foo-plugin/foo-plugin-de_DE.po file should contain:
"""
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"Project-Id-Version: Foo Plugin\n"
"Report-Msgid-Bugs-To: \n"
"X-Domain: foo-plugin\n"
"X-Generator: Poedit 3.0\n"
"X-Poedit-Basepath: ..\n"

#: foo-plugin.php:20
#: foo-plugin.php:10
#: build/index.js:1
#, fuzzy,js-format,php-format
msgid "Hello %s"
msgstr "Hallo %s"
"""
6 changes: 3 additions & 3 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@
</properties>
</rule>

<!-- Whitelist method names for classes that extend a PSR-2 package. -->
<!-- Whitelist method names for classes that follow the naming of the gettext/gettext package. -->
<rule ref="WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid">
<exclude-pattern>*/src/IterableCodeExtractor\.php$</exclude-pattern>
<exclude-pattern>*/src/*(Extractor|Generator|Scanner)\.php$</exclude-pattern>
<exclude-pattern>*/src/Parsed(Comment|Function)\.php$</exclude-pattern>
</rule>

<!-- Whitelist property name for a a JSON-decoded object. -->
<rule ref="WordPress.NamingConventions.ValidVariableName">
<properties>
<property name="allowed_custom_properties" type="array">
<element value="sourcesContent"/>
<element value="functionsScannerClass"/>
</property>
</properties>
</rule>
Expand Down
2 changes: 0 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@ parameters:

treatPhpDocTypesAsCertain: false

stubFiles:
- stubs/Gettext.stub
Loading
Loading