From 00a72efe885b78df133a9293f273581e205ea59b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Indrek=20K=C3=B5nnussaar?= Date: Tue, 30 Apr 2019 19:44:22 +0300 Subject: [PATCH 1/3] Add support for Blade templates --- inc/class-command.php | 8 +++++++- inc/class-wpcodeblade-extractor.php | 25 +++++++++++++++++++++++++ wp-l10n-gen.php | 1 + 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 inc/class-wpcodeblade-extractor.php diff --git a/inc/class-command.php b/inc/class-command.php index 8aca7a1..81b6c09 100644 --- a/inc/class-command.php +++ b/inc/class-command.php @@ -107,7 +107,13 @@ public function generate( $args, $assoc_args = [] ) { if ( isset( $assoc_args['verbose'] ) ) { WP_CLI::log( sprintf( 'Extracting strings from %s', $file_path ) ); } - $translations->addFromWPCodeFile( $file_path ); + + if (stristr($file_path, '.blade.php') !== false) { + $translations->addFromWPCodeBladeFile( $file_path ); + } else { + $translations->addFromWPCodeFile( $file_path ); + } + $progress->tick(); } diff --git a/inc/class-wpcodeblade-extractor.php b/inc/class-wpcodeblade-extractor.php new file mode 100644 index 0000000..7b7b86f --- /dev/null +++ b/inc/class-wpcodeblade-extractor.php @@ -0,0 +1,25 @@ +compileString($string); + } else { + $string = $options['facade']::compileString($string); + } + + parent::fromString($string, $translations, $options); + } + +} \ No newline at end of file diff --git a/wp-l10n-gen.php b/wp-l10n-gen.php index 5020734..9bbe434 100644 --- a/wp-l10n-gen.php +++ b/wp-l10n-gen.php @@ -23,6 +23,7 @@ require_once 'inc/class-multi-filter.php'; require_once 'inc/class-wpfunctionsscanner.php'; require_once 'inc/class-wpcode-extractor.php'; +require_once 'inc/class-wpcodeblade-extractor.php'; require_once 'inc/class-command.php'; WP_CLI::add_command( 'l10n', __NAMESPACE__ . '\Command' ); From 6b621038364d4bca6dd41a16202ab5cd7aaab904 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Indrek=20K=C3=B5nnussaar?= Date: Wed, 22 Jan 2020 22:21:02 +0200 Subject: [PATCH 2/3] Require v4.8.x of gettext library --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c3f5004..76e511d 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "type": "wp-cli-package", "homepage": "https://github.com/roborourke/wp-l10n-gen", "require": { - "gettext/gettext": "dev-master", + "gettext/gettext": "~4.8", "php": ">=5.4" }, "license": "GPL-3.0", From 5fce1b9f69b902fba7a7fad2a173f951b96f5e96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Indrek=20K=C3=B5nnussaar?= Date: Mon, 3 Feb 2020 23:09:11 +0200 Subject: [PATCH 3/3] Remove Translations type hint from saveGettextFunctions() signature to avoid warning --- inc/class-wpfunctionsscanner.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/class-wpfunctionsscanner.php b/inc/class-wpfunctionsscanner.php index eb0ff4c..0cf7a5f 100644 --- a/inc/class-wpfunctionsscanner.php +++ b/inc/class-wpfunctionsscanner.php @@ -14,7 +14,7 @@ class WPFunctionsScanner extends PhpFunctionsScanner { * @param array $options The extractor options * @throws Exception */ - public function saveGettextFunctions( Translations $translations, array $options ) { + public function saveGettextFunctions( $translations, array $options ) { $functions = $options['functions']; $file = $options['file'];