Last active
July 13, 2023 02:32
-
-
Save mcorkum/34e5247bf60f8e8dea8d677719e173be to your computer and use it in GitHub Desktop.
WordPress - Overriding Gutenberg text strings with translations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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