Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Wrong md5 hash generated by i18n-command #177
Comments
Hi there Thanks for raising this. When opening the PO file, what is the path to the JS file that is shown in the string comments? |
@swissspidy So here are a few:
When looking at the path for WP, it's expecting it to be: |
@swissspidy Any progress on this? |
Hi @stuartshields, I came across this issue because I had the same problem a time ago. I think the bug is, that WordPress generates the hash from the relative path to your plugin, so: $md5_filename = $file_base . '-' . md5( $relative ) . '.json';
... and i18n-command/src/MakeJsonCommand.php Lines 198 to 199 in e4edd2f I have solved it by hook into the filter /**
* Allow language overrides so for example de_AT uses de_DE to avoid duplicate
* .po files and management. This is for JavaScript files!
*/
public function load_script_translation_file($file, $handle, $domain) {
$locale = determine_locale();
$pluginFolder = path_join(WPRJSS_PATH, base\Assets::PUBLIC_JSON_I18N);
if ($domain === WPRJSS_TD && !is_readable($file) && substr($file, 0, strlen($pluginFolder)) === $pluginFolder) {
// Collect data
$folder = dirname($file);
$use = $this->override($locale);
$wp_scripts = wp_scripts();
$src = $wp_scripts->registered[$handle]->src;
// Generate new file
$file_base = $domain . '-' . $locale . '-' . md5(basename($src)) . '.json';
return path_join($folder, $file_base);
}
return $file;
} You can not copy&paste the above snippet because it is very related to my boilerplate plugin but you see the idea behind. I hope that helps. |
Let‘s fix the hash then instead of having to use a filter :-) No progress so far because I haven‘t had time to look into this. |
The problem seems to be that wp-cli is using the path of the source files where it found the strings, while WP is using the path of the built files which is of course different. Not sure how to fix this though. |
@kraftner This is a hacky solution, but it seems to work: |
stuartshields commentedJul 31, 2019
•
edited
So I believe this is an issue with how the wp cli command generates the md5 file. I'm going to best describe what happens:
So originally this ticket was created on core - https://core.trac.wordpress.org/ticket/45488 and another ticket in this repo: #120
While the original core ticket has "works for me", I've witnessed this issue first hand over the past week and below is the steps I took to:
mu-plugins
i.e:mu-plugins/gallery
as an example of a namewp_set_script_translations( 'msa-gallery', 'msa-backend' );
is also setwp_set_script_translations( 'msa-blocks', 'msa-backend' );
wp_set_script_translations( 'msa-search', 'msa-backend' );
assets/dist/msa-gallery.js
inside themsa-gallery
folderNote:
msa-gallery
andmsa-backend
aren't our real naming conventions as I've changed these to protect the client project we are working on, however I'm happy to discuss in private the exact naming conventions etc. to help debug this issue.The output file will be something like:
However inside of WP, the language file isn't being loaded at all, Query Monitor shows us that the json file name is:
msa-backend-ja-54e4313a94cbfa7a67f5ea381d70f187.json
An MD5 check on what is generated in WP is correct which is
assets/dist/msa-gallery.js
. However the file generated bywp i18n make-json
is not correct.A way to get around this currently is to rename the json file generated by
wp i18n make-json
to the one that WP expects. Not ideal since the generation of the file should match what is expected in WP itself.Let me know if you need anything else, happy to discuss in private on the names we are using on project.