From 82f93e1336cfef6d69ba318e03497a798d01e017 Mon Sep 17 00:00:00 2001 From: Michael Zangl Date: Mon, 22 Apr 2019 11:19:59 +0200 Subject: [PATCH 1/9] make pot command: Allow .jsx files. --- src/MakePotCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MakePotCommand.php b/src/MakePotCommand.php index cf87d7e6..33cdccef 100644 --- a/src/MakePotCommand.php +++ b/src/MakePotCommand.php @@ -575,7 +575,7 @@ protected function extract_strings() { [ 'include' => $this->include, 'exclude' => $this->exclude, - 'extensions' => [ 'js' ], + 'extensions' => [ 'js', 'jsx' ], ] ); From 9ae86cc5f53399613b9ed84d0231e22696ac8b3b Mon Sep 17 00:00:00 2001 From: Michael Zangl Date: Sat, 27 Apr 2019 21:49:46 +0200 Subject: [PATCH 2/9] Add test that .js and .jsx files are parsed for javascript. --- features/makepot.feature | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/features/makepot.feature b/features/makepot.feature index 2cde3131..acf8393c 100644 --- a/features/makepot.feature +++ b/features/makepot.feature @@ -1638,6 +1638,48 @@ Feature: Generate a POT file of a WordPress project msgid "wrong-domain" """ + Scenario: Parse .js and .jsx files for javascript translations + Given an empty foo-plugin directory + And a foo-plugin/foo-plugin.php file: + """ + Date: Fri, 12 Jul 2019 17:23:21 +0200 Subject: [PATCH 3/9] Add test to cover translator comments with tab indentations --- features/makepot.feature | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/features/makepot.feature b/features/makepot.feature index acf8393c..84c13ce5 100644 --- a/features/makepot.feature +++ b/features/makepot.feature @@ -520,9 +520,15 @@ Feature: Generate a POT file of a WordPress project */ __( 'off', 'foo-plugin' ); - /* translators: this should get extracted. */ $foo = __( 'baba', 'foo-plugin' ); + /* translators: this should get extracted. */ $foo = __( 'baba', 'foo-plugin' ); + + /* translators: boo */ /* translators: this should get extracted too. */ /* some other comment */ $bar = g( __( 'bubu', 'foo-plugin' ) ); + + /* + * translators: this comment block is intend with a tab and should get extracted too. + */ + __( 'yolo', 'foo-plugin' ); - /* translators: boo */ /* translators: this should get extracted too. */ /* some other comment */ $bar = g ( __( 'bubu', 'foo-plugin' ) ); """ When I run `wp i18n make-pot foo-plugin` @@ -568,6 +574,10 @@ Feature: Generate a POT file of a WordPress project """ #. translators: this should get extracted too. """ + And the foo-plugin/foo-plugin.pot file should contain: + """ + #. translators: this comment block is intend with a tab and should get extracted too. + """ Scenario: Generates a POT file for a child theme with no other files When I run `wp scaffold child-theme foobar --parent_theme=twentyseventeen --theme_name="Foo Bar" --author="Jane Doe" --author_uri="https://example.com" --theme_uri="https://foobar.example.com"` From 1ba81067b74cf372e0b120a0c6f5f717a951c5dd Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Fri, 12 Jul 2019 21:05:00 +0200 Subject: [PATCH 4/9] Update test framework to ^2.1.3. See https://github.com/wp-cli/wp-cli-tests/pull/69 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3e6c0fc6..26f827f6 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ }, "require-dev": { "wp-cli/scaffold-command": "^1.2 || ^2", - "wp-cli/wp-cli-tests": "^2.1" + "wp-cli/wp-cli-tests": "^2.1.3" }, "config": { "process-timeout": 7200, From 55c8797f96e3a098f47b8b3627182cf34262cd46 Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Fri, 12 Jul 2019 21:17:43 +0200 Subject: [PATCH 5/9] Insert tab with a placeholder to make it independent of editor configs --- features/makepot.feature | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/features/makepot.feature b/features/makepot.feature index 84c13ce5..6304cd0e 100644 --- a/features/makepot.feature +++ b/features/makepot.feature @@ -494,6 +494,8 @@ Feature: Generate a POT file of a WordPress project """ Scenario: Extract translator comments + Given I run `echo "\t"` + And save STDOUT as {TAB} Given an empty foo-plugin directory And a foo-plugin/foo-plugin.php file: """ @@ -524,11 +526,10 @@ Feature: Generate a POT file of a WordPress project /* translators: boo */ /* translators: this should get extracted too. */ /* some other comment */ $bar = g( __( 'bubu', 'foo-plugin' ) ); - /* - * translators: this comment block is intend with a tab and should get extracted too. - */ - __( 'yolo', 'foo-plugin' ); - + {TAB}/* + {TAB} * translators: this comment block is intend with a tab and should get extracted too. + {TAB} */ + {TAB}__( 'yolo', 'foo-plugin' ); """ When I run `wp i18n make-pot foo-plugin` From 0cb04ce6f62a4ba5c68918b0cafc8dbaa70b6250 Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Sat, 13 Jul 2019 10:51:14 +0200 Subject: [PATCH 6/9] Test: Require specific commit for gettext parser fix --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 26f827f6..2346d9be 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ } ], "require": { - "gettext/gettext": "^4.6", + "gettext/gettext": "dev-master#68d9f76f709a12ad7c3159d0acb08f9cad159426", "mck89/peast": "^1.8", "wp-cli/wp-cli": "^2" }, From e69c38a72c829f99d4886886f6a566a4a867215b Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Mon, 15 Jul 2019 10:58:31 +0200 Subject: [PATCH 7/9] Fix typo Co-Authored-By: Alain Schlesser --- features/makepot.feature | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/makepot.feature b/features/makepot.feature index 6304cd0e..f1cd83bd 100644 --- a/features/makepot.feature +++ b/features/makepot.feature @@ -527,7 +527,7 @@ Feature: Generate a POT file of a WordPress project /* translators: boo */ /* translators: this should get extracted too. */ /* some other comment */ $bar = g( __( 'bubu', 'foo-plugin' ) ); {TAB}/* - {TAB} * translators: this comment block is intend with a tab and should get extracted too. + {TAB} * translators: this comment block is indented with a tab and should get extracted too. {TAB} */ {TAB}__( 'yolo', 'foo-plugin' ); """ @@ -577,7 +577,7 @@ Feature: Generate a POT file of a WordPress project """ And the foo-plugin/foo-plugin.pot file should contain: """ - #. translators: this comment block is intend with a tab and should get extracted too. + #. translators: this comment block is indented with a tab and should get extracted too. """ Scenario: Generates a POT file for a child theme with no other files From fe5ac4b20a82e57545c899e2c2dd9301e8e90635 Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Mon, 15 Jul 2019 16:45:10 +0200 Subject: [PATCH 8/9] Require v4.6.3 of gettext/gettext --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2346d9be..e2c2fb8b 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ } ], "require": { - "gettext/gettext": "dev-master#68d9f76f709a12ad7c3159d0acb08f9cad159426", + "gettext/gettext": "^4.6.3", "mck89/peast": "^1.8", "wp-cli/wp-cli": "^2" }, From e2ded80c1fb167700cbb16af467664ceabac82f3 Mon Sep 17 00:00:00 2001 From: Leo Toikka Date: Fri, 19 Jul 2019 09:25:36 +0300 Subject: [PATCH 9/9] Sort translation files by name to ensure same order on all systems Closes: wp-cli/i18n-command#171. --- src/IterableCodeExtractor.php | 2 ++ tests/IterableCodeExtractorTest.php | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/IterableCodeExtractor.php b/src/IterableCodeExtractor.php index a0e9b148..7edc3f6a 100644 --- a/src/IterableCodeExtractor.php +++ b/src/IterableCodeExtractor.php @@ -234,6 +234,8 @@ function ( $file, $key, $iterator ) use ( $include, $exclude, $extensions ) { $filtered_files[] = Utils\normalize_path( $file->getPathname() ); } + sort( $filtered_files, SORT_NATURAL | SORT_FLAG_CASE ); + return $filtered_files; } } diff --git a/tests/IterableCodeExtractorTest.php b/tests/IterableCodeExtractorTest.php index bdca27f3..d5d29e76 100644 --- a/tests/IterableCodeExtractorTest.php +++ b/tests/IterableCodeExtractorTest.php @@ -110,4 +110,17 @@ public function test_can_override_exclude_by_include() { $expected = static::$base . 'foo/bar/excluded/ignored.js'; $this->assertContains( $expected, $result ); } + + public function test_can_return_all_directory_files_sorted() { + $result = IterableCodeExtractor::getFilesFromDirectory( self::$base, [ '*' ], [], [ 'php', 'js' ] ); + $expected = array( + static::$base . 'baz/includes/should_be_included.js', + static::$base . 'foo-plugin/foo-plugin.php', + static::$base . 'foo/bar/excluded/ignored.js', + static::$base . 'foo/bar/foo/bar/foo/bar/deep_directory_also_included.php', + static::$base . 'foo/bar/foofoo/included.js', + static::$base . 'hoge/should_NOT_be_included.js', + ); + $this->assertEquals( $expected, $result ); + } }