Globalization

Posted by: admin

Fact Check

Globalization is a term applied to websites that support text in different languages. In this tutorial we will examine three different methods of Globalizing a Wordpress theme. As you will see there are cons and pros associated with each method.

The three methods we will try are

  1. Google translate
  2. qTranslate plugin
  3. Language Switcher plugin


Google Translate

This is the simplest of the three translation methods to implement. Copy the script code form the Google Translate home page and incorporate it into one of the pages of your theme such as header.php or sidebar.php (note your site has to be a live site with a valid URL accessible from the internet). This will add a list box where users can select the language of their choice. Selecting the language will automatically convert the text of the page to that language. There are some cons to using Google Translate. First of con is that you may find with certain browsers the translation process modifies the layout of your page so be mindful to test with both IE and FireFox and any other browser you may think your users will have. The second con is that the translation is machine generated so some of the actual context or meaning of the translated text might be lost from the original.

Depending on you connection speed the video may take a few minutes to download. Please wait or try refreshing the browser (F5) if the webcast does not start after a couple of minutes.

Get the Flash Player to see the wordTube Media Player.

4 Real Problems

Adding Google Translate gadget interfered which the page layout when using FireFox.

Links

  1. Google Translate

Wordpress Translation Plugins

The Wordpress Plugins qTranslate and Language Switcher are similar in that they both rely on the different language versions of your post being stored in the wordpress database. Because of this the database character set and collation has to be able to support any laguage character that you may wish to display. Because of this the character set must be utf8 and the collation utf8_general_ci In the tutorial we use the Babel Fish online translator to convert English text into the languages we desire.


qTranslate

This plugin allows you to select which languages that your blog will support via a Settings page in the Wordpress admin. You then add the plugin as a widget on the Appearance Widgets page this will add a drop down control displaying the languages that your blog will be available in. The plugin also modifies the Post and Page Editors where an editor window for each language will be available. You then enter text in the language window in the Post or Page Editor.

Get the Flash Player to see the wordTube Media Player.

4 Real Problems

There was an error on initial install of the plugin but it seemed to work just fine.

Links

  1. qTranslate Plugin home page


Language Switcher

The Language Switcher plugin is similar to qTranslate in as much that you must provide alternative langage text for each language you wish your blog to support. It differs from qTranslate in that it uses the Wordpress core GNU GetText method to convert hard coded file text into the language of choice. Instead of the Post and Page Editors being modified Language Switcher uses a special tag to identify text of a specific language. This is achieved by the translated text being stored in a special File called a POEidt file. This file is read by the GetText method. You need to build a separate POEdit file for each language you want to support. Like qTranslate the Language Switcher has a settings page that allows you to select the languages you wish to support. Language Switcher is more dfficult to set up but gives a slighty more comprehensive translation of the page in that the hard coded text values for example the “Archivies” link can be translated where as with qTranslate this is not possible.

Note the steps below are based on the great article from Gettin’ Geek .

Steps to convert

  1. This line of code to the theme file functions.php
    <?php load_theme_textdomain('text_domain'); ?> 

    This has to go at the top of the file. If you open functions.php you will see that it should start with

     <?php 

    in which case just enter a new line after this and paste

     load_theme_textdomain('text_domain'); 

    . For “text_domain” you can replace this with a name of your choice however make sure that whatever you choose is one string so it does not include spaces or special characters for example “mydomain” is valid however “my domain” is not. Note for the instructions below you would use “mydomain” instead of “text_domain”.

  2. Convert the hard coded text in your theme to use a GetText function call.
    In the tutorial we give the example of modifying the Archives header in sidebar.php where we modify

     Archives 

    to

     <?php _e("Archives", "text_domain"); ?> 

    . This means that the text “Archives” will be now be output to the page via the _e function. See note above to replace “text_domain” with the text domain name you entered in functions.php.

    The other GetText method we mentions the “__” function is used to make text already wrapped within a php function translatable for example you may have

    <?php save_button('Save Draft'); ?>
    

    Modify this to be

    <?php save_button(__('Save Draft', "text_domain")); ?> 

    See note above to replace “text_domain” with the text domain name you entered in functions.php.

    The laborious part of this process is that you have to repeat the above through all the PHP files of the theme internationalizing using the two functions for every instance of text that would previously been output to the page and is hard coded.

  3. Configuring a translation file. Now that your PHP code has all the calls to GetText you then need to provide the translated versions of the text to translate (if you follow:)). You will need to do this for each language you want to translate you you will need to create a translation file containing the translated text. In the tutorial we use POEdit to create a Portable Object file (PO .po extension) which will contain all the translatable words and phrases. POEdit will create a Machine Object file (MO, .mo extension), this file is uploaded to the theme folder on your live site.

    After installing POEdit and using for the first time set the Preference to Automatically compile .mo file on save by File > Preferences, select Editor tab and in the Behavior panel check “Automatically compile .mo file on save” (it may already be checked – if so leave it as it is).
    To create a PO file go to

    • File > New Catalog enter a project name (can be anything)
    • On the second tab Paths click the New Item button which is the square in the Paths panel. You will see a field in the window below appear and in the left field enter the location of your theme code. eg.
      C:\xampp\htdocs\wp4\wp-content\themes\default
    • On the third tab Keywords click the New Item button which again is the square. Here we will enter two items one for the GetText functions “_e” and the second item for the GetText function “__” you will enter these without quotes.
    • After hitting Enter on the Keywords tab POEdit will ask you to give your catalog a name. It is recommended you use the ISO Code for the specific language the file is for.
    • POEdit will then scan the theme folder and files within for calls to the two GetText functions you entered in the keywords tab and you will be presented with a window where you enter the translated version of the text. You do this by clicking on the text you need to translate and then entering the translation in the bottom window. Once you are done with entering all the translations for each string PO Edit found you are finished with this step.

  4. If you haven’t done so already download and install the Language Switcher plugin. After install go to the plugin Settings page.

Language Switcher tutorial Part 1

Get the Flash Player to see the wordTube Media Player.

Language Switcher tutorial Part 2

Get the Flash Player to see the wordTube Media Player.

4 Real Problems

Initially the list of languages that Language Switcher presents to the user so that they can select a language was not present. After some debugging I realized that I had installed the plugin in the wrong folder, I had created a sub folder under the plugins folder where I unzipped the contents of LangSwitch.zip whereas I should of (as per the instructions) unzipped the contents directly to the plugins folder. If installed correctly the file

langswitch.php

should be located in the plugins folder.

Links

  1. Language Switcher Plugin home page
  2. PO Edit
  3. Gettin Geek – Internationalize & Localize a Wordpress Theme – Guide for Dummies – Part 1: Introduction

Previous on Modifying a WordPress Theme

One Response to “Globalization”

  1. MODIFYING A WORDPRESS THEME : WORDPRESS 4 REAL Says:

    [...] « Dashboard Overview Globalization [...]

Categories