Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHILD_TEXT_DOMAIN constant prevents strings being detected #2

Open
nickcernis opened this issue Mar 21, 2017 · 3 comments
Open

CHILD_TEXT_DOMAIN constant prevents strings being detected #2

nickcernis opened this issue Mar 21, 2017 · 3 comments

Comments

@nickcernis
Copy link

nickcernis commented Mar 21, 2017

Current behaviour

The use of the CHILD_TEXT_DOMAIN constant prevents detection of strings by tools such as Loco Translate.

Some translation tools statically analyse files for translation, so CHILD_TEXT_DOMAIN is never parsed by PHP to become 'developers'.

Loco Translate detects only four strings in the theme when trying to create a template file, for example (the ones in stylesheet header) – all of the strings passed to __() are missing:

editing_fr_fr_po_in_developers_ _theme_translations_ _loco_ _wp_dev_ _wordpress

Expected behaviour

CHILD_TEXT_DOMAIN is replaced with a string literal such as 'developers', so that translation tools can detect all strings for translation.

If I find , CHILD_TEXT_DOMAIN and replace with , 'developers', Loco Translate can then find the strings when building the .pot file:

editing_developers_pot_in_developers_ _theme_translations_ _loco_ _wp_dev_ _wordpress

To reproduce

  1. Install and activate Loco Translate.

  2. Create a blank folder named 'languages' in the 'developers' directory. (The theme should probably include this by default, perhaps with a blank index.php inside so it's saved by git?)

  3. Visit Loco Translate → Themes → Developers → Create Template.

  4. Click the “Create template” button:

    new_template_ _developers_ _theme_translations_ _loco_ _wp_dev_ _wordpress 2

The developers.pot template file will be created in the theme's language directory. You can view it directly and count the strings, or see how many strings were detected by clicking “Edit Template” next to the Developers theme in Loco Translate:

developers_ _theme_translations_ _loco_ _wp_dev_ _wordpress 2

11 strings should be found, but you'll only see 4 if the text domain constant is used.

@hellofromtonya
Copy link
Member

hellofromtonya commented Mar 21, 2017

Thank you, Nick. You are correct. If you want to automatically generate the theme's .pot using one of the existing tools on the market, then using a variable or constant won't work. Why? Because these tools use gettext and do not run PHP. It's a UNIX util.

However, I'm teaching a different way of building themes and plugins to be both modular and configurable. That means we need a different way to generate the .pot file. Once we have that file, then the translators can do their job to present the interface and generate the .po files.

New Approach

With this new ModularConfig approach, we will build the .pot for the translators to use.

There's a flaw in the architectural methodology of making developers have to duplicate code over and over again just for building the .pot file. With Modular approach, the idea is to build your code such that you greatly minimize or eliminate having to edit the code within that module. Rather, you pass a configuration file to it for the specific implementation(s).

I'll be teaching and covering that within the next Theme Development A-Z course and am teaching it now in the Plugin Development A-Z course.

I know it's a departure and different. But I'm working to teach folks how to save themselves a lot of time and costs to flourish and grow their careers and businesses.

Notes are needed

I will write an article about it and make a note in the labs for to ensure that folks know that you cannot build a .pot file automatically with the current tools like Poedit.

Thank you for pointing out that I need to make this clear for folks.

Cheers,
Tonya

@nickcernis
Copy link
Author

I really like your config-based approach, and I can see how generating the pot file with gulp or similar might work around the general advice in the WordPress community not to use a variable/constant.

For what it's worth, Poedit found all strings using the “Translate WordPress theme” option even with the constants in place; it was just Loco that struggled to do the same.

@hellofromtonya
Copy link
Member

Thanks, Nick. That's awesome you ran the test with Poedit for me. Thank you so much! I really appreciate you taking the time and digging into it.

Yes, I was going to teach folks both Poedit and Gulp task to build the .pot file. I'll then build a module and hands-on lab to teach folks how to do it and shrink down their code for reusability.

Cheers and thanks again! :)

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

No branches or pull requests

2 participants