Skip to content

Instantly share code, notes, and snippets.

@bikubi
Last active March 3, 2021 15:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bikubi/2cde05d02b3f407452848ce0e83b614e to your computer and use it in GitHub Desktop.
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') }}
#!/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"
@koentjuh1
Copy link

Thanks!

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