Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: wp-cli/i18n-command
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.6.3
Choose a base ref
...
head repository: wp-cli/i18n-command
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 17 commits
  • 13 files changed
  • 2 contributors

Commits on Nov 24, 2024

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    187fe8e View commit details
  2. Copy the full SHA
    0133eb1 View commit details

Commits on Dec 19, 2024

  1. Copy the full SHA
    b7d53ee View commit details
  2. Copy the full SHA
    be093af View commit details
  3. Update test

    Signed-off-by: Pascal Birchler <[email protected]>
    swissspidy committed Dec 19, 2024
    Copy the full SHA
    cd7a72b View commit details
  4. Update test

    Signed-off-by: Pascal Birchler <[email protected]>
    swissspidy committed Dec 19, 2024
    Copy the full SHA
    08a807e View commit details

Commits on Dec 20, 2024

  1. Add test for style variation in subfolder

    Signed-off-by: Pascal Birchler <[email protected]>
    swissspidy committed Dec 20, 2024
    Copy the full SHA
    c44ff63 View commit details
  2. Copy the full SHA
    bf6720f View commit details

Commits on Feb 20, 2025

  1. Copy the full SHA
    58917c7 View commit details
  2. Update another test

    swissspidy committed Feb 20, 2025
    Copy the full SHA
    72105e1 View commit details
  3. update-po: merge X-Domain header

    Adds the header if missing or overrides existing one
    swissspidy committed Feb 20, 2025
    Copy the full SHA
    d230603 View commit details
  4. Copy the full SHA
    c8a94d0 View commit details
  5. Copy the full SHA
    1da09b7 View commit details
  6. Update schema fallback files - 2025-02-20

    wp-make-coffee committed Feb 20, 2025
    Copy the full SHA
    2093be9 View commit details
  7. Merge pull request #431 from wp-cli/update-schemas

    Update schema fallback files
    swissspidy authored Feb 20, 2025
    Copy the full SHA
    e15e904 View commit details

Commits on Feb 21, 2025

  1. Merge pull request #430 from wp-cli/fix/418-make-json-domain

    `make-json`: Add new `--domain` argument
    swissspidy authored Feb 21, 2025
    Copy the full SHA
    c3f6f01 View commit details

Commits on Feb 28, 2025

  1. Merge pull request #428 from wp-cli/fix/427-format-flag

    Add php-format and js-format flags
    swissspidy authored Feb 28, 2025
    Copy the full SHA
    32744a4 View commit details
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -150,7 +150,7 @@ if the source directory is detected as either a plugin or theme.
Extract JavaScript strings from PO files and add them to individual JSON files.

~~~
wp i18n make-json <source> [<destination>] [--purge] [--update-mo-files] [--pretty-print] [--use-map=<paths_or_maps>]
wp i18n make-json <source> [<destination>] [--domain=<domain>] [--purge] [--update-mo-files] [--pretty-print] [--use-map=<paths_or_maps>]
~~~

For JavaScript internationalization purposes, WordPress requires translations to be split up into
@@ -167,6 +167,9 @@ about WordPress JavaScript internationalization.
[<destination>]
Path to the destination directory for the resulting JSON files. Defaults to the source directory.

[--domain=<domain>]
Text domain to use for the JSON file name. Overrides the default one extracted from the PO file.

[--purge]
Whether to purge the strings that were extracted from the original source file. Defaults to true, use `--no-purge` to skip the removal.

69 changes: 44 additions & 25 deletions assets/theme-i18n.json
Original file line number Diff line number Diff line change
@@ -3,33 +3,33 @@
"description": "Style variation description",
"settings": {
"typography": {
"fontSizes": [
{
"name": "Font size name"
}
],
"fontFamilies": [
{
"name": "Font family name"
}
]
"fontSizes": [
{
"name": "Font size name"
}
],
"fontFamilies": [
{
"name": "Font family name"
}
]
},
"color": {
"palette": [
{
"name": "Color name"
}
],
"gradients": [
{
"name": "Gradient name"
}
],
"duotone": [
{
"name": "Duotone name"
}
]
"palette": [
{
"name": "Color name"
}
],
"gradients": [
{
"name": "Gradient name"
}
],
"duotone": [
{
"name": "Duotone name"
}
]
},
"spacing": {
"spacingSizes": [
@@ -45,6 +45,13 @@
}
]
},
"shadow": {
"presets": [
{
"name": "Shadow name"
}
]
},
"blocks": {
"*": {
"typography": {
@@ -69,6 +76,18 @@
{
"name": "Gradient name"
}
],
"duotone": [
{
"name": "Duotone name"
}
]
},
"dimensions": {
"aspectRatios": [
{
"name": "Aspect ratio name"
}
]
},
"spacing": {
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
"eftec/bladeone": "3.52",
"gettext/gettext": "^4.8",
"mck89/peast": "^1.13.11",
"wp-cli/wp-cli": "^2.5"
"wp-cli/wp-cli": "^2.12"
},
"require-dev": {
"wp-cli/scaffold-command": "^1.2 || ^2",
34 changes: 34 additions & 0 deletions features/makejson.feature
Original file line number Diff line number Diff line change
@@ -951,3 +951,37 @@ Feature: Split PO files into JSON files.
And the return code should be 0
And the foo-theme/foo-theme-de_DE-557240f2080a0894dbd39f5c2f559bf8.json file should exist

Scenario: Allows overriding the text domain to use for the file name
Given an empty foo-theme directory
And a foo-theme/de_DE.po file:
"""
# Copyright (C) 2018 Foo Theme
# 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 <LL@li.org>\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-theme\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: foo-theme.js:15
msgid "Foo Theme"
msgstr "Foo Theme"
"""

When I run `wp i18n make-json foo-theme --domain=my-custom-domain`
Then STDOUT should contain:
"""
Success: Created 1 file.
"""
And the return code should be 0
And the foo-theme/my-custom-domain-de_DE-557240f2080a0894dbd39f5c2f559bf8.json file should exist

191 changes: 187 additions & 4 deletions features/makepot.feature
Original file line number Diff line number Diff line change
@@ -2608,6 +2608,7 @@ Feature: Generate a POT file of a WordPress project
"""
#. translators: %s: test
#: foo-plugin.js:1
#, js-format
msgid "Hi %s"
msgstr ""
"""
@@ -3651,6 +3652,35 @@ Feature: Generate a POT file of a WordPress project
msgid "Black"
"""

Scenario: Skips theme.json file if excluding it
Given an empty foo-theme directory
And a foo-theme/theme.json file:
"""
{
"version": "1",
"settings": {
"color": {
"palette": [
{ "slug": "black", "color": "#000000", "name": "Black" }
]
}
}
}
"""

When I try `wp i18n make-pot foo-theme --exclude=theme.json`
Then STDOUT should be:
"""
Success: POT file successfully generated.
"""
And the foo-theme/foo-theme.pot file should exist
But the foo-theme/foo-theme.pot file should not contain:
"""
msgctxt "Color name"
msgid "Black"
"""


Scenario: Extract strings from the top-level section of theme.json files
Given an empty foo-theme directory
And a foo-theme/theme.json file:
@@ -3756,7 +3786,13 @@ Feature: Generate a POT file of a WordPress project
"""

Scenario: Extract strings from style variations
Given an empty foo-theme/styles directory
Given an empty foo-theme directory
And a foo-theme/style.css file:
"""
/*
Theme Name: foo theme
*/
"""
And a foo-theme/styles/my-style.json file:
"""
{
@@ -3774,7 +3810,7 @@ Feature: Generate a POT file of a WordPress project
}
}
"""
And a foo-theme/incorrect/styles/my-style.json file:
And a foo-theme/styles/deeply/nested/variation.json file:
"""
{
"version": "1",
@@ -3791,9 +3827,26 @@ Feature: Generate a POT file of a WordPress project
}
}
"""
And a foo-theme/incorrect/styles/my-style.json file:
"""
{
"version": "1",
"settings": {
"blocks": {
"core/paragraph": {
"color": {
"palette": [
{ "slug": "red", "color": "#ff00000", "name": "Red" }
]
}
}
}
}
}
"""

When I try `wp i18n make-pot foo-theme`
Then STDOUT should be:
Then STDOUT should contain:
"""
Success: POT file successfully generated.
"""
@@ -3803,10 +3856,15 @@ Feature: Generate a POT file of a WordPress project
msgctxt "Color name"
msgid "Black"
"""
And the foo-theme/foo-theme.pot file should not contain:
And the foo-theme/foo-theme.pot file should contain:
"""
msgctxt "Color name"
msgid "White"
"""
And the foo-theme/foo-theme.pot file should not contain:
"""
msgid "Red"
"""

Scenario: Extract strings from the patterns directory
Given an empty foo-theme/patterns directory
@@ -3972,3 +4030,128 @@ Feature: Generate a POT file of a WordPress project
"""
msgid "foo-plugin/longertests/foo-plugin.php"
"""

Scenario: Extract strings from theme.json files in any level
Given an empty foo-project directory
And a foo-project/theme.json file:
"""
{
"version": "1",
"title": "My style variation",
"description": "My style variation description"
}
"""

And a foo-project/nested/theme.json file:
"""
{
"version": "1",
"title": "Nested style variation",
"description": "Nested style variation description"
}
"""

And a foo-project/nested/notatheme.json file:
"""
{
"version": "1",
"title": "Not extracted style variation",
"description": "Not extracted style variation description"
}
"""

When I try `wp i18n make-pot foo-project`
Then STDOUT should be:
"""
Success: POT file successfully generated.
"""
And the foo-project/foo-project.pot file should exist
And the foo-project/foo-project.pot file should contain:
"""
#: theme.json
msgctxt "Style variation name"
msgid "My style variation"
"""
And the foo-project/foo-project.pot file should contain:
"""
#: theme.json
msgctxt "Style variation description"
msgid "My style variation description"
"""
And the foo-project/foo-project.pot file should contain:
"""
#: nested/theme.json
msgctxt "Style variation name"
msgid "Nested style variation"
"""
And the foo-project/foo-project.pot file should contain:
"""
#: nested/theme.json
msgctxt "Style variation description"
msgid "Nested style variation description"
"""
And the foo-project/foo-project.pot file should not contain:
"""
msgid "Not extract style variation"
"""
And the foo-project/foo-project.pot file should not contain:
"""
msgid "Not extracted style variation description"
"""

Scenario: Add php-format and js-format flags for printf usage
Given an empty foo-plugin directory
And a foo-plugin/foo-plugin.php file:
"""
<?php
/**
* Plugin Name: Foo Plugin
* Plugin URI: https://example.com
* Description:
* Version: 0.1.0
* Author:
* Author URI:
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: foo-plugin
* Domain Path: /languages
*/
/* translators: %s: Name */
__( 'Hello %s', 'foo-plugin' );
/* translators: 1: Name */
__( 'Bonjour %1$s', 'foo-plugin' );
"""
And a foo-plugin/foo.js file:
"""
/* translators: %s: Name */
__( 'Hallo %s', 'foo-plugin' );
/* translators: 1: Name */
__( 'Buongiorno %1$s', 'foo-plugin' );
"""

When I run `wp i18n make-pot foo-plugin foo-plugin.pot`
Then the foo-plugin.pot file should contain:
"""
#: foo-plugin.php:16
#, php-format
msgid "Hello %s"
"""
And the foo-plugin.pot file should contain:
"""
#: foo-plugin.php:18
#, php-format
msgid "Bonjour %1$s"
"""
And the foo-plugin.pot file should contain:
"""
#: foo.js:2
#, js-format
msgid "Hallo %s"
"""
And the foo-plugin.pot file should contain:
"""
#: foo.js:4
#, js-format
msgid "Buongiorno %1$s"
"""
Loading