Last active
March 3, 2021 15:04
-
-
Save bikubi/2cde05d02b3f407452848ce0e83b614e to your computer and use it in GitHub Desktop.
Helper script for Roots' Sage starter theme: make WPML's String Translation see WordPress's l10n gettext function in PHP Blade templates, like {{ __('Foo', 'domain') }}
This file contains 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 characters
#!/bin/bash | |
# Scans blade templates for WordPress's gettext functions | |
# so WPML will pick them up for its String Translation. | |
# (WPML doesn't see something like {{ __('Hello World', 'sage') }} | |
# Put me into THEME/resources/assets/build | |
# so $fn will point to THEME/resouces and WPML can see it | |
# (and it's out of sage's way) | |
fn="../../gettexts-fake.php" | |
# prevent execution; doesn't matter for WPML | |
echo "<?php die;" > $fn | |
#NOTE the regex expects somewhat wellformed gettexts with a \w+ domain | |
# like __('Hello', 'domain') | |
find ../../.. -name '*.blade.php' ! -path '*/vendor/*' \ | |
-exec grep -Po "\\b(__|_x|_e|_ex|_n|_nx|esc_html_[_ex]|esc_attr_[_ex])\\(.*?,\\s*[\"\']\w+[\"\']\\s*\\)" \{\} \; \ | |
| sed -e 's/$/;/' >> $fn | |
cat "$fn" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do I execute this?