Engelsystem – Implementing Localization

This post is on how to make your website available in different languages.The main reason of localization is that it can be used by different people knowing different languages across the world and help them to understand the system better .

The tools used in implementing localization are poedit where we create the .po files .

Steps to download poedit and Run it.

sudo apt-get install poedit

On ubuntu/linux this can be used

On Mac/Windows

The executable can be downloaded at https://poedit.net/download

Steps to run poedit in Linux/Windows/Mac

choose File → New Catalog.Enter the details in Translation properties like your email . Source code charset should be selected as UTF-8.Now the source path should be selected as (.) dot to tell Poedit to search for PHP files in the same folder.

Screenshot from 2016-06-04 17:23:39

In the source keywords there are three options ‘_’ , ‘gettext’ and ‘gettext_noop’.Make sure all necessary functions are added and press OK.

Now we can see list of strings and their translated strings comes like this.we need to install the necessary dictionary for this.

Screenshot from 2016-06-04 17:44:25

If we save it we get a .po and .mo files if it passing all the validation.which can be used to implement localization in the project.

How to Use .po and .mo files

In our engelsystem.we need to add the list of languages we would like to implement in the file internationalization_helper.php

$locales = array(
     'de_DE.UTF-8' => "Deutsch",
     'hi_IN.UTF-8' => "Hindi", 
     'sp_EU.UTF-8' => "Spanish",
     'en_US.UTF-8' => "English" 
 );

these are list of languages currently implemented.

function make_langselect() {
   global $locales;
   $URL = $_SERVER["REQUEST_URI"] . (strpos($_SERVER["REQUEST_URI"], "?") > 0 ? '&' : '?') . "set_locale=";
   
   $items = array();
   foreach ($locales as $locale => $name)
     $items[] = toolbar_item_link(htmlspecialchars($URL) . $locale, '', '<img src="pic/flag/' . $locale . '.png" alt="' . $name . '" title="' . $name . '"> ' . $name);
   return $items;
 }

This function renders a language selection.

Development: https://github.com/fossasia/engelsystem

Issues/Bugs:Issues

Continue ReadingEngelsystem – Implementing Localization