b2evolution b2evolution

  • Sign in
  • Sign up
  • About
  • Downloads
  • Hosting
  • Docs
  • Support
  • Sign in
  • Sign up
  • Manuals Home
  • Latest Updates
 
  1. b2evolution CMS User Manual
  2. Advanced Topics
  3. Translations (i18n/l10n)
  4. Localizing Plugins

Localizing Plugins

Plugins that do not get shipped with b2evolution have to provide their own translations.

Inside your plugin’s directory (e.g. example_plugin/), create a directory called locales, where you create a subdirectory and a _global.php file therein for each locale that is supported:


   example_plugin/
      locales/
         messages.pot
         de_DE/
            LC_MESSAGES/
                messages.po
            _global.php
         fr_FR/
            LC_MESSAGES/
                messages.po
            _global.php
         ...

Note: The directory structure is the same as what you have below /blogs/locales/.

To help you generate this, b2evo has a ‘'’xg.php”’ script in /gettext/xg.php. This does not get shipped with releases, but is available from the CVS / SourceForge: http://evocms.cvs.sourceforge.net/evocms/b2evolution/gettext/xg.php?view=markup Get xg.php. You will also need the file _pofile.class.php in the current directory, which you can get also from the http://evocms.cvs.sourceforge.net/viewvc/evocms/b2evolution/blogs/inc/locales/_pofile.class.php?view=log CVS repository.

The process to create this is:

  1. First the plugin needs a messages.pot (PO-template) file. This gets generated whenever some translation strings in the plugin’s source get changed:

mkdir locales/  # if it does not exist yet
php -f xg.php CWD extract
  1. A) Then you’ll need a messages.po file for every language (e.g. for ‘’de_DE'’). You’ll have to do the following only to init the messages.po file of a language (if there is not already one):

mkdir -p locales/''de_DE''/LC_MESSAGES
msginit -i locales/messages.pot -o locales/''de_DE''/LC_MESSAGES/messages.po
  1. B) If there’s already a messages.po file for a locale, you can update it from messages.pot. The following will update locales/de_DE/LC_MESSAGES/messages.po:
php -f xg.php CWD merge ''de_DE''
  1. Edit the messages.po file with a normal text editor or tool like poedit or KBabel. You should normally only have to update untranslated or fuzzy strings.
  1. Convert the messages.po file to the final _global.php file. The following command will create a new de_DE/_global.php file:
php -f xg.php CWD convert ''de_DE''
  1. Send your updated messages.po and _global.php files to the Plugin maintainer (if you are not maintaining it yourself, of course)

Shortcut

Plugins only use the _global.php file, not the messages.pot or messages.po files. The messages files are only important to people who want to translate the Plugin.

So, you do not have to package them with your plugin and if your plugin only has very few strings to be translated, you could even skip the whole procedure above and just create the _global.php files "by hand", in the following way:


 <?php
 $trans[ 'de_DE' ] = array(
   '' => 'Content-Type: text/plain; charset=ISO-8859-1',
   'Hello world!' => 'Hallo Welt!',
   'Hello moon!' => 'Hallo Mond!',
   ...
 );
 ?>

It’s just an array, in fact. But providing the "gettext-Extra-Step" might help your translators a lot, because there are powerful editors for messages.po files available.

Charset

The charset for the localized strings must be supplied in the $trans['xx_XX'] array inside of the ‘’ (empty) key, which is the default gettext behaviour.
E.g., for de_DE it may look like:


$trans['de_DE'] = array(
        '' => 'Project-Id-Version: messages
        Report-Msgid-Bugs-To: http://daniel.hahler.de/
        [...]
        Content-Type: text/plain; charset=ISO-8859-1
        [...]
        X-Generator: KBabel 1.11.2
        ',
 'Captcha images' => 'Captcha Bilder',
 ...
 );

Because "Content-Type:" is the only line used by b2evo, you may also just add '' => 'Content-Type: text/plain; charset=ISO-8859-1', into your _global.php file(s).

Requirements

  • The locales that your plugin supports also need to be supported by b2evo. And the charset of the _global.php file must be the same as defined there (see /conf/_locales.php).
  • The Plugin has to use the Plugin::T_() method, e.g. $this->T_('Hello world!'); (and not the global function with the same name).

Submit plugin translations

If you want to translate some plugin, you basically have to get the existing messages.po file (if there’s any) and update that, or get the template (messages.pot), create a new translation based on it.
Then, submit the messages.po file to the plugin author.

Created by fplanque • Last edit by fplanque on 2020-06-09 00:24 • •

No feedback yet

On this page

  • Shortcut
  • Charset
  • Requirements
  • Submit plugin translations

Search the Manual

Content Hierarchy

  • b2evolution CMS User Manual
  • User's Guide
  • Installation / Upgrade
  • Front-office Reference
  • Back-office Reference
  • Developer Reference
  • Operations Reference
  • Advanced Topics
    • Using Desktop Blogging Tools
    • Using Blogging Apps
    • Blogging by email
    • Using the APIs
    • Contributing
    • Translations (i18n/l10n)
      • How to install a language pack
      • Translating b2evolution
      • Formal vs Casual l10n
      • How to create your own flag / locale
      • Localizing Plugins
      • Localization FAQ
      • Command Line Tools for localization
      • Internationalization (i18n) Guidelines
      • Translation Guidelines
    • Monetizing
    • How to...
    • Podcasting
  • Glossary
  • Archives
Multiple blogs solution

This online manual is powered by b2evolution CMS – A complete engine for your website.

About b2evolution

  • What is it?
  • Features
  • Getting Started
  • Screenshots
  • Online demo
  • Testimonials
  • Design philosophy
  • Free & open source
  • Terms of service

Downloads

  • Latest releases
  • Skins
  • Plugins
  • Language packs

About us

  • About us
  • Contact

Webhosting Guide

  • Web hosting blog
  • Best web hosting
  • Cheap web hosting
  • Green web hosting
  • Hosting with SSH
  • VPS hosting
  • Dedicated servers
  • Reseller hosting
  • Int'l: UK / France

Docs & Support

  • Online manual
  • Forums
  • Hire a pro !

Other

  • Adsense
  • Press room
  • Privacy policy

Stay in touch

  • GitHub
  • Twitter
  • Facebook
  • LinkedIn
  • News blog
  • RSS feed
  • Atom feed

Founded & Maintained by François Planque