Last active
September 27, 2021 09:34
-
-
Save dasilvaluis/ebca42b8b8d70e81f8917f675a784060 to your computer and use it in GitHub Desktop.
Revisions
-
Luís Silva revised this gist
Sep 1, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ "name": "twig-gettext-pot-parser", "version": "1.2.0", "dependencies": { "gulp": "3.9.1", "del": "^3.0.0", "gulp-if": "^2.0.2", "gulp-rename": "^1.2.2", -
Luís Silva revised this gist
Dec 11, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -152,7 +152,7 @@ gulp.task('compile-twigs', () => { // Rename file with .php extension .pipe(rename({ extname: '.php', })) // Output the result to the cache folder as a .php file. .pipe(gulp.dest(config.cacheFolder)); }); -
Luís Silva revised this gist
Dec 11, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ // Init twig engine global $twig; $loader = new Twig_Loader_Filesystem( '/views' ); $twig = new Twig_Environment( $loader, [] ); // Add wordpress gettext functions -
Luís Silva revised this gist
Nov 20, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ <?php /** * Include Wordpress gettext functions in Twig if necessary */ // Init twig engine -
Luís Silva revised this gist
Nov 20, 2018 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ /** * Gettext Scanner Script for Twig Projects * v1.3 * * Developed by Luís Silva * https://github.com/luism-s @@ -16,9 +16,10 @@ * script was built to parse .twig files, wrap occurrences of gettext function calls in php tags and * output the result as a .php file and from that generate a POT file. * It also scans PHP files as well. * * Context: https://github.com/timber/timber/issues/1465 * * Usage: `gulp pot` * * Logic: * - Iterates over all given .twig files -
Luís Silva revised this gist
Nov 20, 2018 . 1 changed file with 67 additions and 81 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -36,13 +36,13 @@ * TODO: * Cover `translate_nooped_plural` function. */ const gulp = require('gulp'); const gulpif = require('gulp-if'); const del = require('del'); const wpPot = require('gulp-wp-pot'); const replace = require('gulp-replace'); const rename = require('gulp-rename'); const runSequence = require('run-sequence'); /** * Configuration Options @@ -51,7 +51,7 @@ var runSequence = require('run-sequence'); * located in the root of the theme and all the Twig * files are located under /views */ const config = { "text_domain" : "theme-test", // Replace with your domain "twig_files" : "views/**/*.twig", // Twig Files "php_files" : "**/*.php", // PHP Files @@ -60,6 +60,50 @@ var config = { "keepCache" : true // Delete cache files after script finishes }; /** * __ * _e * _x * _xn * _ex * _n_noop * _nx_noop * translate -> Match __, _e, _x and so on * \( -> Match ( * \s*? -> Match empty space 0 or infinite times, as few times as possible (ungreedy) * ['"] -> Match ' or " * .+? -> Match any character, 1 to infinite times, as few times as possible (ungreedy) * , -> Match , * .+? -> Match any character, 1 to infinite times, as few times as possible (ungreedy) * \) -> Match ) */ const gettext_regex = { // _e( "text", "domain" ) // __( "text", "domain" ) // translate( "text", "domain" ) // esc_attr__( "text", "domain" ) // esc_attr_e( "text", "domain" ) // esc_html__( "text", "domain" ) // esc_html_e( "text", "domain" ) simple: /(__|_e|translate|esc_attr__|esc_attr_e|esc_html__|esc_html_e)\(\s*?['"].+?['"]\s*?,\s*?['"].+?['"]\s*?\)/g, // _n( "single", "plural", number, "domain" ) plural: /_n\(\s*?['"].*?['"]\s*?,\s*?['"].*?['"]\s*?,\s*?.+?\s*?,\s*?['"].+?['"]\s*?\)/g, // _x( "text", "context", "domain" ) // _ex( "text", "context", "domain" ) // esc_attr_x( "text", "context", "domain" ) // esc_html_x( "text", "context", "domain" ) // _nx( "single", "plural", "number", "context", "domain" ) disambiguation: /(_x|_ex|_nx|esc_attr_x|esc_html_x)\(\s*?['"].+?['"]\s*?,\s*?['"].+?['"]\s*?,\s*?['"].+?['"]\s*?\)/g, // _n_noop( "singular", "plural", "domain" ) // _nx_noop( "singular", "plural", "context", "domain" ) noop: /(_n_noop|_nx_noop)\((\s*?['"].+?['"]\s*?),(\s*?['"]\w+?['"]\s*?,){0,1}\s*?['"].+?['"]\s*?\)/g, }; /** * Main Task */ @@ -71,13 +115,14 @@ gulp.task('pot', function(callback) { * Generate POT file from all .php files in the theme, * including the cache folder. */ gulp.task('generate-pot', () => { const output = gulp.src(config.php_files) .pipe(wpPot({ domain: config.text_domain })) .pipe(gulp.dest(`${config.destFolder}/${config.text_domain}.pot`)) .pipe(gulpif(!config.keepCache, del.bind(null, [config.cacheFolder], { force: true }))); return output; }); /** @@ -93,79 +138,20 @@ gulp.task('generate-pot', function() { * Plural: _n() * Disambiguation: _x(), _ex(), _nx() * Noop: _n_loop(), _nx_noop() */ gulp.task('compile-twigs', () => { del.bind(null, [config.cacheFolder], {force: true}) // Iterate over .twig files gulp.src(config.twig_files) // Search for Gettext function calls and wrap them around PHP tags. .pipe(replace(gettext_regex.simple, match => `<?php ${match}; ?>`)) .pipe(replace(gettext_regex.plural, match => `<?php ${match}; ?>`)) .pipe(replace(gettext_regex.disambiguation, match => `<?php ${match}; ?>`)) .pipe(replace(gettext_regex.noop, match => `<?php ${match}; ?>`)) // Rename file with .php extension .pipe(rename({ extname: '.php', }) // Output the result to the cache folder as a .php file. .pipe(gulp.dest(config.cacheFolder)); }); -
Luís Silva revised this gist
Sep 15, 2018 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,7 +14,8 @@ * While working with Wordpress using the Twig template engine, one might find easier to use gettext * functions in .twig files for string translation. To simplify the scanning of .twig files for those same functions, this * script was built to parse .twig files, wrap occurrences of gettext function calls in php tags and * output the result as a .php file and from that generate a POT file. * It also scans PHP files as well. * * Usage: * `gulp pot` -
Luís Silva revised this gist
Sep 15, 2018 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,6 +7,9 @@ */ /** * Purpose: * Scan Twig and PHP files in the given directories for gettext function calls and output a POT file for translation. * * Description: * While working with Wordpress using the Twig template engine, one might find easier to use gettext * functions in .twig files for string translation. To simplify the scanning of .twig files for those same functions, this -
Luís Silva revised this gist
Sep 15, 2018 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,14 @@ <?php /** * Include Wordpress gettext functions in Twig */ // Init twig engine global $twig; $loader = new Twig_Loader_Filesystem( UAWAPP_PLUGIN_DIR . '/views' ); $twig = new Twig_Environment( $loader, [] ); // Add wordpress gettext functions $twig->addFunction(new Twig_SimpleFunction('__', function( $text, $domain = 'default' ) { return __($text, $domain); } )); -
Luís Silva revised this gist
Sep 15, 2018 . 1 changed file with 22 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ <?php // Init twig engine global $twig; $loader = new Twig_Loader_Filesystem( UAWAPP_PLUGIN_DIR . '/views' ); $twig = new Twig_Environment( $loader, [] ); $twig->addFunction(new Twig_SimpleFunction('__', function( $text, $domain = 'default' ) { return __($text, $domain); } )); $twig->addFunction(new Twig_SimpleFunction('_n', function( $single, $plural, $number, $domain = 'default' ) { return _n($single, $plural, $number, $domain); } )); $twig->addFunction(new Twig_SimpleFunction('_x', function( $text, $context, $domain = 'default' ) { return _x($text, $context, $domain); } )); $twig->addFunction(new Twig_SimpleFunction('_ex', function( $text, $context, $domain = 'default' ) { return _ex($text, $context, $domain); } )); $twig->addFunction(new Twig_SimpleFunction('_nx', function( $single, $plural, $number, $context, $domain = 'default' ) { return _nx($single, $plural, $number, $context, $domain); } )); -
Luís Silva revised this gist
Sep 15, 2018 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,9 +8,8 @@ /** * Description: * While working with Wordpress using the Twig template engine, one might find easier to use gettext * functions in .twig files for string translation. To simplify the scanning of .twig files for those same functions, this * script was built to parse .twig files, wrap occurrences of gettext function calls in php tags and * output the result as a .php file so it can be parsed normally by POEdit. * -
Luís Silva revised this gist
Sep 15, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ /** * Description: * While developing templates using the Twig template engine, one might find easier to use gettext * functions in .twig files for string translation, or wordpress translate functions if it's the case * (Ex: Timber WP Plugin). To simplify the scanning of .twig files for those same functions, this * script was built to parse .twig files, wrap occurrences of gettext function calls in php tags and -
Luís Silva revised this gist
Sep 15, 2018 . No changes.There are no files selected for viewing
-
Luís Silva renamed this gist
Sep 15, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Luís Silva renamed this gist
Sep 15, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Luís Silva revised this gist
May 1, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ { "name": "twig-gettext-pot-parser", "version": "1.2.0", "dependencies": { "gulp": "^3.9.1", "del": "^3.0.0", -
Luís Silva renamed this gist
Apr 20, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Luís Silva renamed this gist
Apr 20, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Luís Silva revised this gist
Apr 1, 2018 . 2 changed files with 16 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ { "name": "twig-gettext-pot-parser", "version": "1.2", "dependencies": { "gulp": "^3.9.1", "del": "^3.0.0", "gulp-if": "^2.0.2", "gulp-rename": "^1.2.2", "gulp-replace": "^0.6.1", "gulp-wp-pot": "^2.2.0", "run-sequence": "^2.2.1" }, "scripts": { "twig-pot": "gulp pot" } } -
Luís Silva revised this gist
Apr 1, 2018 . 1 changed file with 22 additions and 26 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ /** * Gettext Scanner Script for Twig Projects * v1.2 * * Developed by Luís Silva * https://github.com/luism-s @@ -33,7 +33,6 @@ * TODO: * Cover `translate_nooped_plural` function. */ var gulp = require('gulp'); var gulpif = require('gulp-if'); var del = require('del'); @@ -42,7 +41,6 @@ var replace = require('gulp-replace'); var rename = require('gulp-rename'); var runSequence = require('run-sequence'); /** * Configuration Options * @@ -51,17 +49,13 @@ var runSequence = require('run-sequence'); * files are located under /views */ var config = { "text_domain" : "theme-test", // Replace with your domain "twig_files" : "views/**/*.twig", // Twig Files "php_files" : "**/*.php", // PHP Files "cacheFolder" : "views/cache", // Cache Folder "destFolder" : "languages", // Folder where .pot file will be saved "keepCache" : true // Delete cache files after script finishes }; /** * Main Task @@ -72,9 +66,9 @@ gulp.task('pot', function(callback) { /** * Generate POT file from all .php files in the theme, * including the cache folder. */ gulp.task('generate-pot', function() { return gulp.src(config.php_files) .pipe(wpPot( { domain: config.text_domain @@ -92,17 +86,18 @@ gulp.task('generate-pot', function () { * * Functions supported: * * Simple: __(), _e(), translate() * Plural: _n() * Disambiguation: _x(), _ex(), _nx() * Noop: _n_loop(), _nx_noop() * * TODO: * - Support translate_nooped_plural() function * - Skip gettext calls insied Twig comments (ex. {# __('string', 'domain') #}) */ gulp.task('compile-twigs', function() { del.bind(null, [config.cacheFolder], {force: true}) /** * __ * _e @@ -117,7 +112,7 @@ gulp.task('compile-twigs', function(){ * [\'\"] -> Match ' or " * .+? -> Match any character, 1 to infinite times, as few times as possible (ungreedy) * , -> Match , * .+? -> Match any character, 1 to infinite times, as few times as possible (ungreedy) * \) -> Match ) */ var gettext_regex = { @@ -129,21 +124,21 @@ gulp.task('compile-twigs', function(){ // esc_attr_e( "text", "domain" ) // esc_html__( "text", "domain" ) // esc_html_e( "text", "domain" ) simple : /(__|_e|translate|esc_attr__|esc_attr_e|esc_html__|esc_html_e)\(\s*?[\'\"].+?[\'\"]\s*?,\s*?[\'\"].+?[\'\"]\s*?\)/g, // _n( "single", "plural", number, "domain" ) plural : /_n\(\s*?[\'\"].*?[\'\"]\s*?,\s*?[\'\"].*?[\'\"]\s*?,\s*?.+?\s*?,\s*?[\'\"].+?[\'\"]\s*?\)/g, // _x( "text", "context", "domain" ) // _ex( "text", "context", "domain" ) // esc_attr_x( "text", "context", "domain" ) // esc_html_x( "text", "context", "domain" ) // _nx( "single", "plural", "number", "context", "domain" ) disambiguation : /(_x|_ex|_nx|esc_attr_x|esc_html_x)\(\s*?[\'\"].+?[\'\"]\s*?,\s*?[\'\"].+?[\'\"]\s*?,\s*?[\'\"].+?[\'\"]\s*?\)/g, // _n_noop( "singular", "plural", "domain" ) // _nx_noop( "singular", "plural", "context", "domain" ) noop : /(_n_noop|_nx_noop)\((\s*?[\'\"].+?[\'\"]\s*?),(\s*?[\'\"]\w+?[\'\"]\s*?,){0,1}\s*?[\'\"].+?[\'\"]\s*?\)/g }; // Iterate over .twig files @@ -162,11 +157,12 @@ gulp.task('compile-twigs', function(){ .pipe(replace(gettext_regex.noop, function( match ){ return '<?php ' + match + '; ?>'; })) // Rename file with .php extension .pipe(rename(function( file_path ) { file_path.extname = ".php" })) // Output the result to the cache folder as a .php file. .pipe(gulp.dest(config.cacheFolder)); }); -
Luís Silva revised this gist
Dec 29, 2017 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -146,7 +146,10 @@ gulp.task('compile-twigs', function(){ noop : /(_n_noop|_nx_noop)\(\s*([\'\"].+?[\'\"])\s*,\s*([\'\"]\w+?[\'\"])\s*,\s*([\'\"]\w+?[\'\"])\s*\)/g }; // Iterate over .twig files gulp.src(config.twig_files) // Search for Gettext function calls and wrap them around PHP tags. .pipe(replace(gettext_regex.simple, function( match ){ return '<?php ' + match + '; ?>'; })) @@ -162,6 +165,8 @@ gulp.task('compile-twigs', function(){ .pipe(rename(function( file_path ) { file_path.extname = ".php" })) // Output the result to the cache folder as a .php file. .pipe(gulp.dest(config.cacheFolder)); }); -
Luís Silva revised this gist
Dec 29, 2017 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -32,7 +32,6 @@ * * TODO: * Cover `translate_nooped_plural` function. */ var gulp = require('gulp'); -
Luís Silva revised this gist
Dec 29, 2017 . 1 changed file with 3 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,19 +24,17 @@ * - Scan all .php files for gettext functions using 'gulp-wp-pot' (cache included) * - Generate .pot file * * Dependencies: * `npm install gulp gulp-if del gulp-wp-pot gulp-replace gulp-rename run-sequence` * * Warning: * This script has only ben tested in the context of Wordpress theme development using Timber. * * TODO: * Cover `translate_nooped_plural` function. * */ var gulp = require('gulp'); var gulpif = require('gulp-if'); var del = require('del'); -
Luís Silva revised this gist
Dec 29, 2017 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -29,8 +29,7 @@ * This script has only ben tested in the context of Wordpress theme development using Timber. * * TODO: * Cover `translate_nooped_plural` function. */ /** -
Luís Silva revised this gist
Dec 29, 2017 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -84,7 +84,7 @@ gulp.task('generate-pot', function () { domain: config.text_domain } )) .pipe(gulp.dest(config.destFolder + '/' + config.text_domain + '.pot')) .pipe(gulpif(!config.keepCache, del.bind(null, [config.cacheFolder], {force: true}))); }); /** @@ -150,7 +150,7 @@ gulp.task('compile-twigs', function(){ noop : /(_n_noop|_nx_noop)\(\s*([\'\"].+?[\'\"])\s*,\s*([\'\"]\w+?[\'\"])\s*,\s*([\'\"]\w+?[\'\"])\s*\)/g }; gulp.src(config.twig_files) .pipe(replace(gettext_regex.simple, function( match ){ return '<?php ' + match + '; ?>'; })) -
Luís Silva revised this gist
Dec 29, 2017 . 1 changed file with 39 additions and 19 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,28 +1,42 @@ /** * Gettext Scanner Script for Twig Projects * v1.1.1 * * Developed by Luís Silva * https://github.com/luism-s */ /** * Description: * While developing templates using the Twig Template Engine, one might find easier to use gettext * functions in .twig files for string translation, or wordpress translate functions if it's the case * (Ex: Timber WP Plugin). To simplify the scanning of .twig files for those same functions, this * script was built to parse .twig files, wrap occurrences of gettext function calls in php tags and * output the result as a .php file so it can be parsed normally by POEdit. * * Usage: * `gulp pot` * * Logic: * - Iterates over all given .twig files * - Search and replace for gettext functions in Twig files and wraps them around PHP tags * - Outputs each file as .php into a cache folder * - Scan all .php files for gettext functions using 'gulp-wp-pot' (cache included) * - Generate .pot file * * * Warning: * This script has only ben tested in the context of Wordpress theme development using Timber. * * TODO: * Cover `translate_nooped_plural`function usage * */ /** * Dependencies: * * `npm install gulp gulp-if del gulp-wp-pot gulp-replace gulp-rename run-sequence` */ var gulp = require('gulp'); var gulpif = require('gulp-if'); @@ -70,7 +84,7 @@ gulp.task('generate-pot', function () { domain: config.text_domain } )) .pipe(gulp.dest(config.destFolder + '/' + config.text_domain + '.pot')) .pipe(gulpif(!config.pot.keepCache, del.bind(null, [config.pot.cacheFolder], {force: true}))); }); /** @@ -111,26 +125,32 @@ gulp.task('compile-twigs', function(){ * \) -> Match ) */ var gettext_regex = { // _e( "text", "domain" ) // __( "text", "domain" ) // translate( "text", "domain" ) // esc_attr__( "text", "domain" ) // esc_attr_e( "text", "domain" ) // esc_html__( "text", "domain" ) // esc_html_e( "text", "domain" ) simple : /(__|_e|translate|esc_attr__|esc_attr_e|esc_html__|esc_html_e)\(\s*([\'\"].+?[\'\"])\s*,\s*([\'\"]\w+?[\'\"])\s*\)/g, // _n( "single", "plural", number, "domain" ) plural : /(_n)\(\s*([\'\"].*?[\'\"])\s*,\s*([\'\"].*?[\'\"])\s*,\s*(.+?)\s*,\s*([\'\"]\w+?[\'\"])\s*/g, // _x( "text", "context", "domain" ) // _ex( "text", "context", "domain" ) // esc_attr_x( "text", "context", "domain" ) // esc_html_x( "text", "context", "domain" ) // _nx( "single", "plural", "number", "context", "domain" ) disambiguation : /(_x|_ex|_nx|esc_attr_x|esc_html_x)\(\s*([\'\"].+?[\'\"])\s*,\s*([\'\"].+?[\'\"])\s*,\s*([\'\"].+?[\'\"])\s*\)/g, // _n_noop( "singular", "plural", "domain" ) // _nx_noop( "singular", "plural", "context", "domain" ) noop : /(_n_noop|_nx_noop)\(\s*([\'\"].+?[\'\"])\s*,\s*([\'\"]\w+?[\'\"])\s*,\s*([\'\"]\w+?[\'\"])\s*\)/g }; gulp.src(config.pot.twig_files) .pipe(replace(gettext_regex.simple, function( match ){ return '<?php ' + match + '; ?>'; })) -
Luís Silva revised this gist
Dec 29, 2017 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,11 +19,11 @@ * - Generate .pot file */ /** * Dependencies: * * `npm install gulp gulp-if del gulp-wp-pot gulp-replace gulp-rename run-sequence --save-dev` */ var gulp = require('gulp'); var gulpif = require('gulp-if'); var del = require('del'); -
Luís Silva revised this gist
Dec 29, 2017 . 1 changed file with 17 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -111,10 +111,23 @@ gulp.task('compile-twigs', function(){ * \) -> Match ) */ var gettext_regex = { // _e( "text", "domain" ) // __( "text", "domain" ) // translate( "text", "domain" ) simple : /(__|_e|translate)\(\s*([\'\"].+?[\'\"])\s*,\s*([\'\"]\w+?[\'\"])\s*\)/g, // _n( "single", "plural", number, "domain" ) plural : /(_n)\(\s*([\'\"].*?[\'\"])\s*,\s*([\'\"].*?[\'\"])\s*,\s*(.+?)\s*,\s*([\'\"]\w+?[\'\"])\s*/g, // _x( "text", "context", "domain" ) // _ex( "text", "context", "domain" ) // _nx( "single", "plural", "number", "context", "domain" ) disambiguation : /(_x|_ex|_nx)\(\s*([\'\"].+?[\'\"])\s*,\s*([\'\"].+?[\'\"])\s*,\s*([\'\"].+?[\'\"])\s*\)/g, // _n_noop( "singular", "plural", "domain" ) // _nx_noop( "singular", "plural", "context", "domain" ) noop : /(_n_noop|_nx_noop)\(\s*([\'\"].+?[\'\"])\s*,\s*([\'\"]\w+?[\'\"])\s*,\s*([\'\"]\w+?[\'\"])\s*\)/g }; gulp.src(config.twig_files) -
Luís Silva revised this gist
Dec 29, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ * Gettext Scanner Script for Twig Projects * v1.0.1 * * Developed by Luís Silva * https://github.com/luism-s */ -
Luís Silva revised this gist
Dec 29, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -41,7 +41,7 @@ var runSequence = require('run-sequence'); * files are located under /views */ var config = { "text_domain" : "text_domain", // Replace with your domain "twig_files" : [ // Twig Files "views/**/*.twig" ],
NewerOlder