→ 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.
At first, it is easier to develop it in your language. I recommend to use language files after the plugin becomes stable.
If your plugin name is NP_AbcDef, plugin directory name is abcdef (always lower case).
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).
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).
Replace static strings in your plugin with the defined names so they will change according to the language file.
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.
As English is the default language, it is recommended to have at least the English version.