WooThemes

WooThemes

Account Login

The WooThemes Blog

All the latest news and announcements, straight from the WooThemes HQ!

Subscribe

Our Themes, Your Language

09. Nov, 2009 by Adii Rockstar in WooThemes News

localizationA few weeks ago, the whole WooTeam combined for a massive hustle in localizing all of our 40-odd themes (at that stage). This meant re-doing large chunks of the static text that we had included, to enable us to use GNU’s “gettext” functions. This means that all of our themes now includes one file (.po) which is used for easy translation of our themes, without the need to edit the core template files.

So… We’d like to launch a new initiative, whereby our themes will be translated into as many languages as possible. There’s obviously a lot of value in this for us and we’d like to reward everyone that actually contributes some translations to the project. How cool would it be to have every WooTheme available in 20-odd languages?

Continue Reading »

How to translate a theme

26. Aug, 2009 by Magnus in All Themes

How to setup a language file in WordPress

All of our themes have a /lang/ folder, which holds all the translated files, called .po (Portable Object File) and .mo (Machine Object File). To activate WP with your language file you need to do the following steps:

1. Copy your .mo language file from the themename/lang/themename-xx_XX.mo (e.g. busybee/lang/busybee-es_ES.mo) to the root of your theme folder, and remove the theme name prefix, so only the language and country code make up the filename, for example

busybee/es_ES.mo

2. Edit your wp-config.php file and add this to it

define ('WPLANG', 'es_ES');

Remember to replace the parameter ‘es_ES’ with your language and country code (or ‘es’ if you only have a language code and no country code).

NOTE: If you only use a language code and no country code in wp-config.php, then simply name your ‘mo’ file with the country code (e.g. busybee/es.mo). The wp-config.php and your filename must be the same.

This is all that is needed to activate your language with your theme.

How to translate a theme from scratch

Background info

WordPress uses a standard localization framework called GNU gettext. This framework provides the programmer the ability to mark text inside code as being suitable for localization. The role of the translator is to take these marked pieces of text and produce a language-specific localization. No code needs to change and you do not need to understand how the program works.

Text is marked by wrapping it with special PHP functions. It is not important to know how these functions work, but it will be helpful to recognize them:

  • __($text) – Looks for a translated version of $text and returns the result
  • _e($text) – Looks for a translated version of $text and echo the result to the screen (i.e. effectively it is echo __($text))
  • __ngettext($single,$plural,$number) – If $number is 1 then looks for a translated version of $single. If number is more than 1 then looks for a translated version of $plural.

(Source: Urban Giraffe)

Translating WooThemes
Putting this into context, it means that all our text in our template files (.php files) have been wrapped in gettext functions. This enables us to create a Portable Object File (or .po file) which contains all the text for the theme. This has already been done by us at WooThemes.

The user (that’s you) then has the ability to use a program (we’ll get back to this later) to translate this .po file into another language, add it to the theme directory, and have a translated theme!

Before we start

Before you can start to translate the theme, you need to make sure that the theme has been made ready for translation. All our new themes will support localization and include a language file (.po file) which contains all the English texts, and soon all our old themes will be upgraded as well.

If you are not certain if your theme has been made ready for translation/localization, you can simply check if there is a “/lang/themename.po” file in your theme folder. If there isn’t one, you will need to download the latest version of the theme and check if the .po file existst there. If it does include a translation file, you will need to upgrade your theme to be able to translate it.

How to translate

To translate your theme, you will need to use Poedit to translate the included Portable Object file (.po file), which will then create a Machine Object file (.mo file) which we will upload to our theme folder for WordPress to read.

Follow these steps to translate your .po file into another language and make a .mo file:

  1. Download and install Poedit, the program we will use to translate our .po file.
  2. Open the themename.po file found in your /lang/ folder with poedit.
  3. Now go through and translate all the text one line at a time in the bottom box.
  4. Save the file after you’re done. This will output a .po and .mo file.
Translating the .po file with Poedit

Translating the .po file with Poedit

You can also consider using this WordPress plugin, which allows you to translate our default .po file directly in the WP admin panel.

Setup WordPress
Before we can upload our new .mo file, we need to make sure we named it correctly, as it has to match your desired language locale. See the complete list of language codes and country codes to find your exact locale.

We’ll use Norwegian as the example here, so first we find the language code (nb – Norsk BokmÃ¥l) and the country code (NO). We than rename our .mo file to nb_NO.mo and upload to the root of our theme folder e.g.

wp-content/themes/themename/nb_NO.mo

The last step is to make sure your WordPress config file, wp-config.php, is setup with your locale, which in this case is Norwegian. So open wp-config.php and check that what you have in your define() function. For Norwegian it will look like this:

define ('WPLANG', 'nb_NO');

Once you have matched the wp-config.php setting to our .mo filename, you should have successfully translated your WooTheme into another language.

Share your language

We want to make it easier for users to get the theme in their language, so if you have translated your theme into your language, we hope you can share the .mo file with us, so new users don’t have to translate the theme themselves.

Please send us your translated files (.po and .mo) files to support@woothemes.com and we will put your file up in our repository.

them