PHP Classes

How to Use a PHP Localization Library to Implement Internationalized PHP Applications Using the Package Localizer: Get localized texts in PHP, JavaScript and Python

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2025-08-27 (2 days ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
localizer 2.0.0Artistic License5Localization, PHP 5
Description 

Author

This package can get localized texts in PHP, JavaScript and Python.

It provides a PHP class that can return the text translation for an application language in one of several supported languages.

The text translations are provided in the form of arrays for each of the supported languages.

The class can also get the plural of a given text using a callback function.

Simple, but versatile, class for localization (l10n) for PHP, JavaScript, Python

Picture of Nikos M.
Name: Nikos M. is available for providing paid consulting. Contact Nikos M. .
Classes: 19 packages by
Country: Greece Greece
Age: 48
All time rank: 8449 in Greece Greece
Week rank: 195 Up2 in Greece Greece Up
Innovation award
Innovation award
Nominee: 8x

Winner: 2x

Instructions

Example

<?php
// php test.php | out-file -filepath out.txt -encoding utf8
// or
// php test.php > out.txt

require(dirname(__FILE__) . '/../../src/php/Localizer.php');

$l10n = new Localizer();
// setup supported locales
$l10n->locale('en', []);
$l10n->locale('el', [
   
'I want to say {0}' => '???? ?? ?? {0}',
   
'hello to you' => '???? ?? ????',
   
'hello to all' => '???? ?? ?????',
   
'@' => [
       
// specific context
       
'ctx1' => [
           
'hello to you' => '???? ?? ???? ????',
        ],
    ],
]);
// set current locale
$l10n->locale('el', true);

// UTF8 BOM
define('UTF8_BOM', chr(0xEF).chr(0xBB).chr(0xBF));
echo
UTF8_BOM;

echo
'Localizer::VERSION = ' . Localizer::VERSION . PHP_EOL;
echo
$l10n->locale() . PHP_EOL;
echo
$l10n->l('hello to you') . PHP_EOL;
echo
$l10n->l('hello to all') . PHP_EOL;
echo
$l10n->l('hello to you', '???? ?? ????') . PHP_EOL;
echo
$l10n->l('hello to all', '???? ?? ?????') . PHP_EOL;
echo
$l10n->l('I want to say {0}', [$l10n->l('hello to you')]) . PHP_EOL;
echo
$l10n->l('I want to say {0}', [$l10n->l('hello to all')]) . PHP_EOL;
echo
$l10n->ln(1, 'hello to you', 'hello to all') . PHP_EOL;
echo
$l10n->ln(2, 'hello to you', 'hello to all') . PHP_EOL;
echo
$l10n->l('hello to you', '???? ?? ???? ????') . PHP_EOL;
echo
$l10n->l(['hello to you','ctx1']) . PHP_EOL;


Details

Localizer

Simple, but versatile, class for localization (l10n) for PHP, JavaScript, Python

version 2.0.0

Example

$l10n = new Localizer();

// setup supported locales
$l10n->locale('en', []); // en is 1st
$l10n->locale('el', [ // el is 2nd
    'I want to say {0}' => '???? ?? ?? {0}',
    'hello to you' => '???? ?? ????',
    'hello to all' => '???? ?? ?????',
    '@' => [
        // specific context
        'ctx1' => [
            'hello to you' => '???? ?? ???? ????',
        ],
    ],
]);

// set current locale
$l10n->locale('el', true);

echo 'Localizer::VERSION = ' . Localizer::VERSION . PHP_EOL;

// get current locale
echo $l10n->locale() . PHP_EOL;

// localize by lookup
echo $l10n->l('hello to you') . PHP_EOL;
echo $l10n->l('hello to all') . PHP_EOL;

// localize by choosing based on active locale
echo $l10n->l('hello to you', '???? ?? ????') . PHP_EOL;
echo $l10n->l('hello to all', '???? ?? ?????') . PHP_EOL;

// localize with custom arguments
echo $l10n->l('I want to say {0}', [$l10n->l('hello to you')]) . PHP_EOL;
echo $l10n->l('I want to say {0}', [$l10n->l('hello to all')]) . PHP_EOL;

// localize singular/plural
echo $l10n->ln(1, 'hello to you', 'hello to all') . PHP_EOL;
echo $l10n->ln(2, 'hello to you', 'hello to all') . PHP_EOL;

// localize based on specific context
echo $l10n->l('hello to you', '???? ?? ???? ????') . PHP_EOL;
echo $l10n->l(['hello to you','ctx1']) . PHP_EOL;

see also:

  • ModelView a simple, fast, powerful and flexible MVVM framework for JavaScript
  • tico a tiny, super-simple MVC framework for PHP
  • LoginManager a simple, barebones agnostic login manager for PHP, JavaScript, Python
  • SimpleCaptcha a simple, image-based, mathematical captcha with increasing levels of difficulty for PHP, JavaScript, Python
  • Dromeo a flexible, and powerful agnostic router for PHP, JavaScript, Python
  • PublishSubscribe a simple and flexible publish-subscribe pattern implementation for PHP, JavaScript, Python
  • Localizer a simple and versatile localization class (l10n) for PHP, JavaScript, Python
  • Importer simple class &amp; dependency manager and loader for PHP, JavaScript, Python
  • EazyHttp, easy, simple and fast HTTP requests for PHP, JavaScript, Python
  • Contemplate a fast and versatile isomorphic template engine for PHP, JavaScript, Python
  • HtmlWidget html widgets, made as simple as possible, both client and server, both desktop and mobile, can be used as (template) plugins and/or standalone for PHP, JavaScript, Python (can be used as plugins for Contemplate)
  • Paginator simple and flexible pagination controls generator for PHP, JavaScript, Python
  • Formal a simple and versatile (Form) Data validation framework based on Rules for PHP, JavaScript, Python
  • Dialect a cross-vendor &amp; cross-platform SQL Query Builder, based on GrammarTemplate, for PHP, JavaScript, Python
  • DialectORM an Object-Relational-Mapper (ORM) and Object-Document-Mapper (ODM), based on Dialect, for PHP, JavaScript, Python
  • Unicache a simple and flexible agnostic caching framework, supporting various platforms, for PHP, JavaScript, Python
  • Xpresion a simple and flexible eXpression parser engine (with custom functions and variables support), based on GrammarTemplate, for PHP, JavaScript, Python
  • Regex Analyzer/Composer Regular Expression Analyzer and Composer for PHP, JavaScript, Python

  Files folder image Files (11)  
File Role Description
Files folder imagesrc (3 directories)
Files folder imagetest (3 directories)
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (11)  /  src  
File Role Description
Files folder imagejs (1 file)
Files folder imagephp (1 file)
Files folder imagepy (2 files)

  Files folder image Files (11)  /  src  /  js  
File Role Description
  Accessible without login Plain text file Localizer.js Data Auxiliary data

  Files folder image Files (11)  /  src  /  php  
File Role Description
  Plain text file Localizer.php Class Class source

  Files folder image Files (11)  /  src  /  py  
File Role Description
  Accessible without login Plain text file Localizer.py Data Auxiliary data
  Accessible without login Plain text file __init__.py Data Auxiliary data

  Files folder image Files (11)  /  test  
File Role Description
Files folder imagejs (2 files)
Files folder imagephp (2 files)
Files folder imagepy (2 files)

  Files folder image Files (11)  /  test  /  js  
File Role Description
  Accessible without login Plain text file out.txt Doc. Documentation
  Accessible without login Plain text file test.js Data Auxiliary data

  Files folder image Files (11)  /  test  /  php  
File Role Description
  Accessible without login Plain text file out.txt Doc. Documentation
  Accessible without login Plain text file test.php Example Example script

  Files folder image Files (11)  /  test  /  py  
File Role Description
  Accessible without login Plain text file out.txt Doc. Documentation
  Accessible without login Plain text file test.py Data Auxiliary data

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads  
 100%
Total:0
This week:0