0

I have developed seven Wordpress plugins for a new project as I was not able to find anything that currently supported these features. Three of them have interest from other users and one of those other users runs a multi-language multi-site.

I'm therefore looking at internationalisation. I have reviewed the documentation here but am at a loss. https://developer.wordpress.org/themes/functionality/internationalization/

Firstly many plugins I have downloaded from the Wordpress.org do not contain a text-domain for the plugin contrary to what is stated here. Secondly, some of these plugins also use react components.

My preference is not to bother directly translating strings myself based on different locales but to allow the system to do it for me (assuming it supports it). There is nothing complicated about any of these strings as they are mostly just input labels.

So what is the correct approach:

<?php echo __('Enter a title'); ?> or <?php echo __('Enter a title', $plugin_name); ?> or neither.

And in react __("Enter a title") or __("Enter a title", plugin-name) or neither.

And I also read something about not using variables for the text domain in these internationalisation strings. Does that mean they need to be hard typed in every single place.

Thanks,

1 Answer 1

1

Yes, the text domain should be used.

PHP

The WordPress Documentation you referenced says:

The text domain is the second argument that is used in the internationalization functions. The text domain is a unique identifier, allowing WordPress to distinguish between all of the loaded translations.

React

On the JavaScript (React) side, below the heading How to use i18n in JavaScript and above the text Common functions available on the Internationalization page of the WordPress Block Editor Handbook Documentation it says:

The second argument is the text domain which must match the text domain slug specified by your plugin.

Hard typed text domains

Text domains should be hard-typed, and should not be variables. At the bottom of the section titled "Add text domain to strings", the documentation says:

The text domain should be passed as a string to the localization functions instead of a variable. It allows parsing tools to differentiate between text domains. Example of what not to do:
__( 'Translate me.' , $text_domain );


The user of the multi-language multi-site may already be implementing an approach to internationalisation that you could follow. Otherwise, there are several options available to give you some idea of where to start looking.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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