MM 2.2.6+


MemberMouse includes support for localization, and by default loads a US English translation for use with the plugin. It’s possible to translate most text in the MemberMouse backend to the language of your choice using WordPress’ built-in localization feature. This is in addition to being able to create member-facing content in the language of your choice with few exceptions. These are detailed in the second half of this article.


The simplest way to add support for additional languages is to use a localization plugin and the Translate MemberMouse - Basic article walks through the steps for that approach. But if there is more specific customization you'd like to achieve, support can also be added programmatically using a small amount of code. While this code can be placed in many different locations, it is probably best to create a small plugin dedicated to translation, which is what will be demonstrated in this article and explained in more detail below.



Translate MemberMouse Backend - Advanced


In order to translate the backend from English to the language of your choice, you will need to create a translation file or "Localization" file. The file that holds this translation is appended by .po / .mo, where .po is the editable file and the .mo is the compiled version. By defining a proper configuration, WordPress will use this file to do the work based on the language selected. Localization using .po / .mo files is a basic way to translate phrase “x” to phrase “y” in the new respective language. If done correctly, you might have something like the following:



English/Spanish Example:

“How are you?” = “Como Estas?”



How it works: Construction of a .po file


The .po file is really a simple file that does the translation as mentioned above. The language file is typically named in the following manner:

[text-domain]-[language-prefix]_[Country]


text-domain: mm (Our plugin has a text domain of “mm” by default.)

language-prefix: List of Language-Codes

Country: List of Country-Codes


Ex. If you want to translate to German and are located in Germany, the file name would be: mm-de_DE 



A typical basic file might look something like the following:

File: mm-es_ES.po

   

msgid ""

msgstr ""

"Project-Id-Version: Spanish Version 1.0\n"

"POT-Creation-Date: \n" 

"PO-Revision-Date: \n" 

"Last-Translator: \n" 

"Language-Team: MemberMouse <support@membermouse.com>\n" 

"MIME-Version: 1.0\n"

"Content-Type: text/plain; charset=iso-8859-1\n" 

"Content-Transfer-Encoding: 8bit\n" "Language: es_ES\n"

"X-Generator: Poedit 1.8.8\n" 

"Plural-Forms: nplurals=2; plural=(n != 1);\n"

"X-Poedit-SourceCharset: UTF-8\n"


msgid "How are you?" 

msgstr "Como Estas?"

   

As you can see the msgid is the text to be translated and the msgstr is the resultant translated phrase. Atop of the translation, is just some metadata to help define the language and version.


Additional Information: There is some reading on plural forms found here: Poedit Plural Forms



Advanced Translation Setup


NOTE: The following contains advanced steps that will take time, effort and planning to accomplish:



  1. Download MemberMouse - The first step is to obtain the latest version of MemberMouse. This will prompt you to save a zip file named membermouse.zip. Place this file in a known location that you have read and write access to.

  2. Create a folder for the new plugin - The next step is to create a folder/directory on the local filesystem to hold the files we will create for our new plugin. The folder can be named anything. For this example we will use the name membermouse-translation.

  3. Unzip the MemberMouse Plugin - After the “membermouse-translation” folder has been created, locate the MemberMouse plugin downloaded in step 1, and unzip the plugin into a known location. The unzip process will create a folder named “membermouse”.


  4. Copy the language files into the new plugin's folder – Inside of the "membermouse" folder that was created above, will be another folder called “languages”. This folder needs to be copied into the “membermouse-translation” folder.



  5. Download the Poedit application – Poedit is a free application used to edit translation files for applications that use gettext (like WordPress). The latest version can be downloaded from here: POEdit Download

  6. Create a New Translation - Open the Poedit application, and choose “Create New Translation” from the main screen, and select the membermouse.po file in the membermouse-translation/languages folder.




  7. Select Language to Translate to - In the next dialog that appears, select the language you would like to create a translation for (Note: if you just want to customize some of the English labels, select English(US) from the dropdown).




  8. Translate Desired Text Fields - Selecting your desired language will open a window with all of the text available for translation in a scrolling area. Select the items you wish to translate, and in the “Translation” textbox, type the translated text.




  9. Save the New Translation - When you are satisfied with your translation, go to the File menu, choose “Save As” and save the new .po for your language in the languages folder. The format of this file is very important, it should be “membermouse-<locale>.po”. Fortunately, Poedit will pre-populate the filename field with the correct locale for the language you selected, so you just need to add “membermouse-” in front of that. For example, for English(US), Poedit will pre-populate the filename field with “en_US.po”, so adding “membermouse-” yields the filename “membermouse-en_US.po”. Once the filename has been entered correctly, save the new .po file in the membermouse-translation/languages folder. If the language is English(US), it will ask if you want to overwrite the existing .po file, answer yes to this.




    After the .po file has been saved, go to the File menu and select “Compile to .mo”. Create a .mo file in the membermouse-translation/languages with the same name as the .po file, with the extension changed to .mo. For example, using English(US), create a .mo file named “membermouse-en_US.mo”.


     



  10. Create the main plugin file - Create a file in the membermouse-translation folder named membermouse-translation.php. The code that will be placed in this file is mostly WordPress plugin boilerplate code, with a special block added in to substitute in the translation created in the previous step when MemberMouse attempts to load its translation files. Add the following code to the file:

    <?php

    /*

    Plugin Name: MemberMouse Translation

    Plugin URI: http://www.membermouse.com/

    Description: A translation for MemberMouse

    Version: 1.0

    */

    function membermouse_translation_override_load_textdomain($mofile, $domain)

    {

    if ('membermouse' === $domain) {

    return plugin_dir_path(__FILE__).'languages/membermouse-

    en_US.mo'; }

    return $mofile;

    }

    add_filter( 'load_textdomain_mofile','membermouse_translation_override_load

    _textdomain', 10, 2 );



  11.  Modify the code as needed - If the .mo file for the new translation is different than the one in the membermouse-translation.php file, modify the line that reads

    return plugin_dir_path(__FILE__).'languages/membermouse-en_US.mo';

    and change “membermouse-en_US.mo” to match the .mo file created in step 7.


  12. Zip and Install the New Plugin – Create a compressed zip file named “membermouse-translation.zip” that contains the folder “membermouse-translation” and its contents. This zip is now a fully-functioning WordPress plugin that can be installed to override the default translation! You would simply install this updated plugin following the same steps outlined in the article Installing MemberMouse



Translate Member-Facing Content


Most of the things that your customers will be interacting with via your website and member portal can be translated as the majority of customer-facing content that MemberMouse creates is simply HTML text that can be modified via the WordPress editor. There are a few instances where items can either not be translated, or require more coding than just changing the HTML in order to translate. Wherever possible we've suggested other methods of translating these elements.


Elements able to be translated with additional coding: 


  1. Error messages generated by MemberMouse or error messages received from 3rd parties, such as the payment service provider.
    If you are technically inclined you can customize this message to appear in another language. The Customize Error Messages on the Checkout Page article provides additional information on how to do this. You'll note in this article that you can translate the 3rd party error messages only if you know the specific error message received from the 3rd party that you want to translate.

  2. The product price descriptionA workaround would be to create product-specific custom checkout pages and replace the [MM_Form_Data name='productPriceDescription'] SmartTag with text in your language describing the pricing for that product. The Create a Custom Checkout Page article provides additional information on how to do this.

  3. The payment processing message on the checkout page that displays after a customer has submitted their order.  You can customize this message to appear in another language by following the information provided in Customize the Checkout Page Processing Message


Because messages coming from 3rd party vendors, such as payment service providers, are received and then directly output by MemberMouse onto the screen, if you do not know the specific error message from the 3rd party vendor, then this will not be able to be translated.