plugindev:internationalize

HOW-TO: Internationalize Your Plugins

Back to Plugin Development index

Written by Andy Matsubara

I was annoyed by making versions for multiple languages (or character encodings). So I decided to introduce language files for my plugins. Following is a step by step guide to how to do it.

1. Develop your plugin

At first, it is easier to develop it in your language. I recommend to use language files after the plugin becomes stable.

2. Create plugin directory

If your plugin name is NP_AbcDef, plugin directory name is abcdef (always lower case).

3. Create language files

Create the language files in the directory of your plugin. The name of the language file must be seme as Nucleus language file name. For example, english.php is for English and default use. japanese-utf8.php for Japanese(UTF-Cool,japanese-euc.php for Japanese(EUC-JP).

4. Define strings

Define strings like below in the language file:

<?php
define('_ABCDEF_MESSAGENAME',                  'actual strings in the language');
  .
    .
    .
?>

You have to define them for all static strings in your plugin. As defined name is used globally in the environment, it is recommended to have a prefix same as plugin name(in this case _ABCDEF).

5. Replace static strings

Replace static strings in your plugin with the defined names so they will change according to the language file.

6. Create init method

Make the init method in the plugin like below

   function init() {
      // include language file for this plugin
      $language = ereg_replace( '[\\|/]', '', getLanguageName());
      if (file_exists($this->getDirectory().$language.'.php'))
         include_once($this->getDirectory().$language.'.php');
      else
         include_once($this->getDirectory().'english.php');
   }

This logic is same as Nucleus’ language file setting.

7. Add language files

As English is the default language, it is recommended to have at least the English version.

 
plugindev/internationalize.txt · Last modified: 2006/07/05 13:03