Currently, Business Directory uses the standard WordPress string externalization mechanism (PO files) to allow you to translate the plugin to any language you wish. We also support the use of WPML if you prefer. We are transitioning to a wordpress.org-based translation method so you can contribute to our translated strings there. If you are interested in being a contributor or a translator, we would appreciate your contributions. You can see our progress on translations on WordPress.org here: https://translate.wordpress.org/projects/wp-plugins/business-directory-plugin/
This article explains how to create a single-language translation file.
The Translation file can serve TWO purposes:
- To change the language Business Directory Plugin is displayed in from English to something else
- To change labels, strings and messages that you see in English to whatever you want (also in English)
Choose the proper steps based on which workflow you are following.
Please note–Business Directory Plugin does ship with SOME translations already completed for you! Please look under wp-content/plugins/business-directory-plugin/languages on your site server for the available files.
How to translate Business Directory to another language
Every time a we release a new version, we add, edit or remove strings in the plugin, and as a result, those strings are changed in the translation files. If you are using a translation file, you should update your translation files with EACH upgrade of the plugin.
All the strings can be translated and verified over at translate.wordpress.org. Any of the completed languages (90% translation or higher) should be translated there, and then the new values are immediately pushed out to everyone using that language.
If your language is not yet at 90%, you can add your translations there, then click the Export link at the bottom of the page. For example, take a look at export link at the bottom of the Stable version translation page. Once exported, you can upload the .po and .mo files in the business-directory-plugin/languages folder.
How to translate a module
Business Directory Plugin can be translated into any language, per the WordPress text internationalization standards. For more general information about how WordPress supports externalized strings for plugins, please read this article first.
- Start with the POT file from Business Directory Plugin (in the wp-content/plugins/business-directory-plugin/languages directory of the plugin, named business-directory-plugin.pot)
- Downloaded the POedit software.
- Translate all strings to your preferred language following the instructions in the POEdit documentation
- Save the file as business-directory-plugin-<langcode_COUNTRY>.po, where <langcode_COUNTRY> represents your ISO language code/country combination, such as en_US (English, US), en_UK (English, UK), fr_FR (French, France), pt_BR (Portuguese, Brazil), etc. Country codes can be found on this GNU website.
- Upload this new language-coded file to the wp-content/languages/plugins/ on your website’s server (if it does not exist, please CREATE this directory first).
- The language of the website should be configured directly through General Settings section in the WordPress Dashboard: http://YOURSITE//wp-admin/options-general.php, where YOURSITE is replaced by the domain name of your WordPress site. Pick the correct language setting and be sure to Save Settings. For more information on doing this, see this WordPress Codex page on Installing WordPress in your Language.
- IMPORTANT: Be sure to flush any browser caching you have in addition to any WordPress/web hosting caching you have so that you can see your new strings.
- You should now see your site in the new language, with a few exceptions (see below!)
This will translate about 95% of the plugin. Further translation must happen in the following places, which are stored in the database:
- Your Business Directory Plugin page name must be translated to your native language (under Pages → All Pages)
- Strings that are inside the configuration (see under Directory → Settings), such as the Terms and Conditions (General tab), the Submit Listing and Sticky Listing messages (Listings tab) must be translated
- Email templates (under Directory → Settings → Email) must be translated
- Update all field labels, by going to Directory → Directory Content → Form Fields
After you do all of these, Business Directory Plugin is fully translated.
NOTE: Some languages like English and Spanish have variants depending on the country, however Greek and many other languages do not have variants so they do not require the _COUNTRY part in the name: business-directory-plugin-{langcode_COUNTRY}.po, only langcode is required.
You can visit https://translate.wordpress.org/ and check to see if your language has variants and requires the country, or if langcode is enough:
Where should I upload the translation file?
Translations files for other languages (business-directory-plugin-<language_COUNTRY>.po and business-directory-plugin-<language_COUNTRY>.mo) can be uploaded to one of the following locations:
1) wp-content/languages/plugins/ (RECOMMENDED)
2) <plugin-directory>/languages/ (DEFAULT)
3) <plugin-directory>
<plugin-directory> is usually /wp-content/plugins/business-directory-plugin.
The best practice is to store custom translations in wp-content/languages/plugins/, because that way the translations won’t be deleted during an upgrade. Options 2 and 3 above will be overwritten on upgrade.
Load translation file from other location
To avoid a translation file from getting overwritten on updates, you may move the po and mo files to a different location.
The file wp-content/languages/business-directory-plugin/business-directory-plugin-en_US.mo
, if present, will always be loaded (for users in “English/US” domains), allowing users to overwrite the translation of specific strings. They can create translation files that include only the strings that they want to change. WordPress will use their translations for those strings and use the ones provided by plugin in other cases.
Then, the plugin will check for each of the following files, in the given order, until one of them can be loaded.
wp-content/plugins/business-directory-plugin/languages/business-directory-plugin-en_US.mo
Generated by us, included in the plugin.
wp-content/plugins/business-directory-plugin/business-directory-plugin-en_US.mo
Previous versions included the translations files in here, in the plugin’s root directory.
wp-content/languages/plugins/business-directory-plugin-en_US.mo
WordPress checks for files in this location automatically.
Business Directory also supports the use of WPML to do translations as well. We cover how to configure that in this article.
Furthermore, here’s a guide for translating WP plugins in general (including language codes, naming conventions, and encodings):
http://urbangiraffe.com/articles/translating-wordpress-themes-and-plugins/
Spanish Translation: Special Guidelines
As mentioned earlier in this article, we are transitioning to a wordpress.org-based translation method so you can contribute to our translated strings there. The Spanish modules are complete, thus the .po and .mo files will no longer work to translate Spanish.
That said, there still may be times when you want to translate parts of the pre-translated Spanish we have provided. This section shows you how to do this.
The easiest way possible to do this is to create a plugin using our instructions here. We recommend the free Pluginception plugin editor for this.
The next step is to create the code you need for your translation. Paste the code below into your new plugin (I called mine BD Spanish Custom):
———————————-
add_filter( 'gettext', 'bd_change_listing_names', 20, 3 ); function bd_change_listing_names( $translated_text, $text, $domain ) { if ( $domain === 'business-directory-plugin' ) { $search = array('anuncio', 'search'); $replace = array('listados', 'encontrar'); $translated_text = str_replace( $search, $replace, $translated_text ); } return $translated_text; }
———————————-
In the example I've shown above, the translations are shown in the $search and $replace sections.
The $search placeholder is where you place the words that need to be replaced and in the $replace placeholder, that's where you place the actual translations for those words.
Please remember to do translations of all variations of the words you are replacing. For example, if you were changing the word anuncio, you would also need to add a translation for anuncios.
Once the new translation plugin you have created is installed and activated, you will see the new translations on your site!