Skip to content
This repository has been archived by the owner on Dec 4, 2022. It is now read-only.

I it necessary to add the text domain in gettext calls? #3

Closed
alialaa opened this issue Nov 30, 2018 · 6 comments
Closed

I it necessary to add the text domain in gettext calls? #3

alialaa opened this issue Nov 30, 2018 · 6 comments

Comments

@alialaa
Copy link

alialaa commented Nov 30, 2018

Hello, in your code here I can see that you use the text domain as a second argument for __, but in the Gutenberg handbook it's mentioned that you can put it but you don't have to. Do you have any idea if it's necessary or not and if not why do we have the option to put it?

@swissspidy
Copy link
Owner

Great question!

I‘d argue the handbook is wrong in that case. Gutenberg itself omits the text domain for various reasons, one being that the code is used in WordPress core. But it‘s considered a best practice to always pass it.

I actually wrote a detailed explanation for that on my blog: https://pascalbirchler.com/text-domain-wordpress-internationalization/

@alialaa
Copy link
Author

alialaa commented Nov 30, 2018

Thanks for your answer, correct if I am wrong but your article is only dealing with PHP gettext calls right? maybe JS ones don't need them for some reason?

@alialaa
Copy link
Author

alialaa commented Nov 30, 2018

also one more question if the wp i18n command already scans js files, why do we need @wordpress/babel-plugin-makepot to scan js files and then merge php and js translations with wp i18n? why not use wp 18n directly?

@swissspidy
Copy link
Owner

No, it also applies to JavaScript files.

In the end it boils to what you‘re developing.

If you‘re developing a WordPress plugin and use the WP I18N package for internationalization, there‘s no need to use that Babel plugin at all. That plugin was like an intermediate solution for everything. It‘s basically outdated now. You can now just use the WP-CLI command to generate everything.

@alialaa
Copy link
Author

alialaa commented Dec 1, 2018

Thanks a lot :)

@swissspidy
Copy link
Owner

Opened an issue in the Gutenberg repository to improve the documentation: WordPress/gutenberg#12502

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants