Environment
- Lando dev with WordPress recipe
- PHP 8.1
- Sage 10 theme
The Problem
I’m trying to set up JavaScript translations for my Sage theme. I’ve generated a PO file with translations for my JavaScript files and I’m using wp i18n make-json
to convert it to JSON format. However, the JSON files are never loaded because WordPress is looking for files with different hash names than those generated by wp-cli.
My command:
bash
lando wp i18n make-json ./resources/lang --no-purge --pretty-print
This generates files with names like:
sage-pl_PL-c0e883ba376de980b2740a4c676091cd.json
But looking at the debug log, WordPress is trying to load files with different hashes:
[03-May-2025 07:46:19 UTC] Loading translation file for handle: shipping_subscriptions/0, domain: sage, file: /app/wp/wp-content/themes/pimp_my_lashes/resources/lang/sage-pl_PL-shipping_subscriptions/0.json
[03-May-2025 07:46:19 UTC] Loading translation file for handle: shipping_subscriptions/0, domain: sage, file: /app/wp/wp-content/themes/pimp_my_lashes/resources/lang/sage-pl_PL-2c8a875cb7a780ac3461f69f750a1810.json
[03-May-2025 07:46:19 UTC] Loading translation file for handle: shipping_subscriptions/0, domain: sage, file: /app/wp/wp-content/languages/plugins/sage-pl_PL-2c8a875cb7a780ac3461f69f750a1810.json
Here’s how I register my script in Sage:
php
// Enqueue scripts and styles with localized data
bundle('shipping_subscriptions')
->enqueueCss()
->enqueueJs(true, ['wp-element', 'wp-api-fetch'])
->localize('shippingSubscriptionsAPI', [
'root' => esc_url_raw(rest_url('owline/v1')),
'nonce' => wp_create_nonce('wp_rest'),
])
->translate('sage', get_template_directory() . '/resources/lang');
My PO file contains entries like:
#: resources/scripts/admin/shipping-subscription/App.js:62
msgid "Shipping Subscriptions Management"
msgstr "PimpMyDelivery"
Questions
- How does WordPress determine which hash to use when looking for JS translation files?
- How can I make
wp i18n make-json
generate JSON files with the same hash that WordPress is looking for? - Is there a way to debug or modify the hash generation process?
Any help would be greatly appreciated as I’ve been stuck on this issue for some time!