Translation files not working
-
Hi the .po and .mo files inside languages folder are not working, I think it is because they are missing the textdomain in the .po file.
Shouldn’t it be:
#@ bp-invite-anyone #: group-invites/templates/invite-anyone.php:35 #: group-invites/templates/invite-anyone.php:126 msgid "Select members from the directory:"Instead of:
#: group-invites/group-invites.php:219 #: group-invites/group-invites.php:314 msgid "Select members from the directory:"Also changing the filenames invite-anyone.po/.mo to bp-invite-anyone.po/.mo would be helpful when working with translation plugins such as https://wordpress.org/plugins/codestyling-localization/, since by default this plugin searches for bp-invite-anyone.po and it can’t find a custom name such as invite-anyone.po.
It is also good practice to use this naming convention according to WordPress:
The .mo file should be named based on the domain followed by a dash, and then the locale exactly.
I had to use the following workaround to get it working (for Spanish only, if you need other languages repeat the process changing the locale part es_ES):
cp wp-content/plugins/invite-anyone/languages/invite-anyone-es_ES.po wp-content/plugins/invite-anyone/languages/bp-invite-anyone-es_ES.poUsing plugin codestyling localization, go to Tools > Localization, search for invite anyone, a Spanish file will appear now since we copied it manually before. Click on Scan again, this will add the missing textdomain ID to each string:
#@ bp-invite-anyoneThen clic on Edit, change translations as desired and clic on generate mo-file.
Add this to your theme’s functions.php file:
if( !function_exists( 'cp_load_theme_textdomain' ) ) { function cp_load_theme_textdomain(){ unload_textdomain('bp-invite-anyone'); load_plugin_textdomain('bp-invite-anyone', false, '../languages/plugins/'); } add_action('after_setup_theme', 'cp_load_theme_textdomain'); }And move the files we have created to a new location where they will not be lost when updating the plugin:
mv wp-content/plugins/invite-anyone/languages/bp-invite-anyone-es_ES.* wp-content/languages/plugins/The drawback is that if we need to edit translations again, we need to move them back to wp-content/plugins/invite-anyone/languages/ for codestyling localization to find them.
The topic ‘Translation files not working’ is closed to new replies.