Skip to content

Commit 5810c1e

Browse files
author
Indrek Kõnnussaar
committed
Add support for Blade templates
1 parent f61ab88 commit 5810c1e

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

inc/class-command.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,13 @@ public function generate( $args, $assoc_args = [] ) {
107107
if ( isset( $assoc_args['verbose'] ) ) {
108108
WP_CLI::log( sprintf( 'Extracting strings from %s', $file_path ) );
109109
}
110-
$translations->addFromWPCodeFile( $file_path );
110+
111+
if (stristr($file_path, '.blade.php') !== false) {
112+
$translations->addFromWPCodeBladeFile( $file_path );
113+
} else {
114+
$translations->addFromWPCodeFile( $file_path );
115+
}
116+
111117
$progress->tick();
112118
}
113119

inc/class-wpcodeblade-extractor.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Gettext\Extractors;
4+
5+
use Gettext\Extractors\WPCode;
6+
use Gettext\Translations;
7+
use Illuminate\Filesystem\Filesystem;
8+
use Illuminate\View\Compilers\BladeCompiler;
9+
10+
class WPCodeBlade extends WPCode implements ExtractorInterface {
11+
12+
public static function fromString( $string, Translations $translations, array $options = [] ) {
13+
14+
if (empty($options['facade'])) {
15+
$cachePath = empty($options['cachePath']) ? sys_get_temp_dir() : $options['cachePath'];
16+
$bladeCompiler = new BladeCompiler(new Filesystem(), $cachePath);
17+
$string = $bladeCompiler->compileString($string);
18+
} else {
19+
$string = $options['facade']::compileString($string);
20+
}
21+
22+
parent::fromString($string, $translations, $options);
23+
}
24+
25+
}

0 commit comments

Comments
 (0)