Skip to content

Instantly share code, notes, and snippets.

@mcorkum
Last active July 13, 2023 02:32
Show Gist options
  • Save mcorkum/34e5247bf60f8e8dea8d677719e173be to your computer and use it in GitHub Desktop.
Save mcorkum/34e5247bf60f8e8dea8d677719e173be to your computer and use it in GitHub Desktop.
WordPress - Overriding Gutenberg text strings with translations
{
"domain": "messages",
"locale_data": {
"messages": {
"": {
"domain": "messages"
},
"This block contains unexpected or invalid content.": [
"Poop, this block sucks now"
]
}
},
"comment": {
"reference": "wp-includes/js/dist/block-editor.js"
}
}
<?php
// Filter for loading custom json to override the gutes.
add_filter('load_script_translation_file', 'override_core_translation_file', 10, 3);
function override_core_translation_file($file, $handle, $domain)
{
// Specify the script handle for which you want to replace the translations.
if ('default' === $domain) {
// Path to your custom JSON translation file.
// In this case in a folder 'languages' relataive to this file.
$file = plugin_dir_path(__FILE__) . 'languages/test.json';
}
return $file;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment