Can we use a variable hook for language string?

Yes this is problematic as i18n tools that parse your theme to generate a *.pot file for translation can’t understand this as they do not run PHP code but just search your code as text.

Here is a blogpost detailing on why this may cause trouble:

Bottom line: Inside all translation functions, no PHP variables are allowed in the strings, for any reason, ever. Plain single-quoted strings only.

But nevertheless the fact that you think about DRY is great! Actually as I’ve already talked about the i18n tools they can help you with automatically adding a textdomain. There even is a Grunt plugin to automate this plus the option to replace/rename textdomains which would solve your actual issue. Just comment if you need more help on that.

Leave a Comment