7

I am working on a theme and I want to make it available for translating. I have not been including a text domain on translated text because I don't know what the text domain is going to be yet. I figured, until I can come up with a name for my theme I should just use a function to output my text domain name instead of hard coding it on translated text.

EXAMPLE:

This is the traditional way of adding a text domain:

echo _e('Hello', 'my-theme-name');

my approach is like this:

function text_domain() {
   define('TEXT_DOMAIN', 'my-theme-name', true );
   echo TEXT_DOMAIN;
}

and using like this:

 echo _e('Hello', text_domian());

...and when I do come up with a name for my theme I can just update it in one place instead a bunch of times in every file.

THE QUESTION IS: Is this an ok way to do it and will I encounter problems getting my theme approved by the WordPress theme review team?

14

No, this is not okay. NO NO NO. Here's my favourite Otto quote:

Inside all translation functions, no PHP variables are allowed in the strings, for any reason, ever.

Otto explains this in more detail, but the simple way to say it is that translation calls are parsed, not executed . So your variable (let alone your function) may not be evaluated and the text-domain breaks.

So, you're better off using a unique name like wpse241589 for your textdomain temporarily and do a search and replace once you have a better name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.