Skip to content

Instantly share code, notes, and snippets.

Embed
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') }}
#!/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"
@broskees
Copy link

broskees commented Mar 7, 2019

How do I execute this?

@koentjuh1
Copy link

koentjuh1 commented Jan 29, 2020

Thanks!

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