Skip to content

Instantly share code, notes, and snippets.

Last active March 3, 2021 15:04
What would you like to do?
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') }}
# 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)
# 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"
Copy link

broskees commented Mar 7, 2019

How do I execute this?

Copy link


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment