stalno u pokretu

< IT & tech

17. 09. 2014. back end * fuelphp * i18n&l10n * laravel * php

PHP internationalization frameworks: Laravel and FuelPHP

I originally published this article on Lingohub blog in 2013, while working for the company. Lingohub specializes in providing app localization for developers and translators.</a>

This is our concluding article on PHP internationalization frameworks and i18n prep tutorials. Our previous articles have covered the following aspects:

The last article in this series on PHP internalization will cover two more PHP frameworks that are frequently used: Laravel and FuelPHP. Thanks also to previous commenters that have expressed interest in covering Laravel in more detail.

PHP internationalization frameworks: The Laravel framework

Internationalization in the Laravel framework can be done by the use of the PHP array files, stored within app/lang directory. Language files for each language should be stored in their own subdirectory:


The language files should return an array of keyed strings:

The keys should be chosen carefully, because if the language line for the active language does not exist, the key will be returned. Laravel does not allow specifying a fall-back language.

The default language can be set in the app/config/app.php, and the active language can be changed using the App::setLocale method like this:


The lines can be retrieved from the language files with the get method of the Lang class. The argument passed to the get method consists of two segments, first one being the name of the language file, and the second one the key of the line that should be retrieved.

echo Lang::get('days.monday');

The presence of the translation for the specific key and active language can be checked with the has method:

if (Lang::has('days.monday')){

Place-holders can be defined in the language files, and substituted with the dynamic values during the run time:

  return array(
    'welcome' => 'Welcome, :username'

The substitute values are passed to the get method in an array as a second argument:

echo Lang::get('messages.welcome', array('username' => $username));

A singular form can be separated from a plural form in the translations by the use of the “pipe” character:

  return array(
    'apples' => 'There is one apple|There are many apples'

The Lang::choice method can be used to retrieve the line:

echo Lang::choice('messages.apples', 10);

Laravel translator is powered by the Symfony Translation component, so more explicit pluralization rules can easily be created:

  return array(
    'apples' => '{0} There are none|[1,19] There are some|[20,Inf] There are many'

Further reading:

PHP internationalization frameworks: The FuelPHP framework

The Lang class of FuelPHP framework allows setting up language variables using language files. The default language (en) is set in app/config/config.php. The Config:set method can be used to change that value:

Config::set('language', 'de');

FuelPHP also allows defining of fall-back language in  the configuration, which is either a language code or an array of language codes.

An example of app/config/config.php :

Several resource file formats are supported by FuelPHP:

PHP array files are the default type. They have similar key-value structure as previously described for Laravel framework.

INI files. I have already covered this resource file type in an article of its own.

YAML files. We have covered these as well, you can find the article here.

JSON files. You can read about resjson files, json resource files used in the Windows applications developed for Windows 8 in this article.

The language resource files are loaded with the load method of the Lang class. If the resource file type is not specified, Lang::load will default to “php array” type.

Specific lines are retrieved from the language file with the Lang::get method. The one required parameter of the get method is the key of the phrase that should be returned. Optional parameters are: $parameters – an array of parameters used to replace the place-holders, $default – value to return if the key can not be found and $language – language code for which the line should be retrieved; if not given, the current active language is used.

For other methods of the Lang class, you can check the official FuelPHP documentation.


Further reading:

This concludes our series of articles on the PHP i18n. It should give you an idea how website internationalization is implemented across the PHP world, and help you make the necessary steps so that your websites can be more accessible to wider audience. Once that is clear, get ready for localization. Talk to us if we can help you prepare to roll out your applications in many languages.

Related posts

17. 09. 2014. back end * cakephp * codeigniter * i18n&l10n * php * symfony * yii * zend
Internationalization How To for the 5 most popular PHP frameworks

In this how-To you will read about using CodeIgniter, CakePHP, Zend, Yii and Symfony
[ reading time: ~ 8 min. ]

17. 09. 2014. back end * i18n&l10n * php
PHP internationalization – i18n mechanisms tutorial

Static web and internationalization, dynamic web applications, localizing strings directly in the code, storing the strings in a relational database, message catalogues (string arrays), JSON, use of resource files
[ reading time: ~ 10 min. ]

17. 09. 2014. back end * gettext * i18n&l10n * php
PHP internationalization with gettext tutorial

Installation, portable object template files, plurals, an example of a PO file, directory structure, machine object files, gettext caching problems, setting up PHP for internationalization with gettext...
[ reading time: ~ 18 min. ]

17. 09. 2014. back end * i18n&l10n * ruby
i18n gem advanced features – Ruby on Rails internationalization

Using Different Backends for Ruby i18n gem, chaining backends, caching is an i18n gem advanced feature, fallbacks, Translation Metadata, cascading lookups, translation symlinks, using custom exception handlers
[ reading time: ~ 15 min. ]

17. 09. 2014. back end * i18n&l10n * padrino * ruby * sinatra
Internationalization for Ruby – i18n gem

i18n for plain Ruby & the i18n gem, i18n for Ruby on Rails, i18n for Sinatra, i18n for Padrino
[ reading time: ~ 20 min. ]

17. 09. 2014. back end * i18n&l10n * ruby
Internationalization for Ruby with the r18n gem

Installation and setup, translation lookup, filters for translations processing, pluralization, translating activeRecord models and plain Ruby objects, locale settings, r18n wrappers for rails and sinatra, r18n vs i18n
[ reading time: ~ 9 min. ]

17. 09. 2014. back end * i18n&l10n
Resource file formats

ini files, properties files, iOS .strings files, YAML files, RESX and RESW files, RESJSON files
[ reading time: ~ 4 min. ]

17. 09. 2014. back end * gettext * i18n&l10n * ruby
Ruby gettext internationalization tutorial on using the fast_gettext gem

Setup, translation lookup, managing translations (MO/PO, db, yaml), rails plugin, pluralization, defaults, multiple repositories, logging...
[ reading time: ~ 9 min. ]

10. 08. 2014. api * back end
Representational state transfer (REST)

[ reading time: ~ 3 min. ]

15. 08. 2014. api * back end * ruby
API - design, implementation, testing

notes and resources
[ reading time: ~ 3 min. ]

01. 09. 2014. api * back end * bdd / tdd * cucumber * ruby * ruby gem
Developing rails REST API with Cucumber

json_spec, writing the definitions, checking the http headers, testing authentication...
[ reading time: ~ 3 min. ]

03. 09. 2014. api * back end * ruby * ruby gem * security
Devise as authentication solution for rails API

Authentication token, the use of sessions, intsallation and setup, configuring the model, the routes, application controller, custom devise controllers, testing the controllers
[ reading time: ~ 9 min. ]

04. 09. 2014. api * back end
Design principles of the REST-ful JSON API (HATEOAS)

REST, JSON, API, HATEOAS, media types, top level resource representations, url templates, compound documents, urls, responses, errors, JSend response types, HTTP Status codes
[ reading time: ~ 12 min. ]

07. 09. 2014. api * back end * ruby
Building a JSON API in rails

[ reading time: ~ 1 min. ]

12. 09. 2014. back end * ruby
ActiveRecord notes

Uniqueness on a combination of fields, inclusion in array, getting all model associations, overriding model getters and setters, serialization...
[ reading time: ~ 2 min. ]

22. 11. 2014. back end * deployment * ruby
rails deployment

Setting up Debian 7 server on VPS, nginx, php-fpm, ruby, unicorn/phusion passanger, essentials, ssh keys, capistrano...
[ reading time: ~ 2 min. ]

24. 11. 2014. back end * dev_tool
nginx notes

[ reading time: ~ 1 min. ]

10. 12. 2014. back end * ruby gem

[ reading time: ~ 1 min. ]

Ovaj sajt ne sadrži first party kukije i druge mehanizme za aktivno praćenje poseta/ponašanja (facebook, google analytics, itd...). Na nekim stranicama se nalaze embedovani youtube video klipovi i google mape koji učitavaju svoje kukije.