2017 © Pedro Peláez
 

library i18n

Simple Component for internationalizing

image

biniweb/i18n

Simple Component for internationalizing

  • Monday, March 31, 2014
  • by biniweb
  • Repository
  • 0 Watchers
  • 0 Stars
  • 23 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

PHP i18n

Simple PHP i18n, (*1)

Some of its features:, (*2)

  • Translations in ini-files
  • Return array of translation (suitable also for Mustache engine template)

Setup

To use the i18n class, look at the test/example.php or test/example_mustache.php and test/example_mustache.html. You will find there a simple tutorial for this class in the file. Otherwise follow these easy five steps:, (*3)

1. Create language files

To use this class, you have to use ini files for the translated strings. This could look like this:, (*4)

en.ini (English), (*5)

greeting = "Hello World!"

[category]
somethingother = "Something other..."

de.ini (German), (*6)

greeting = "Hallo Welt!"

[category]
somethingother = "Etwas anderes..."

2. Initialize the class

example.php, (*7)

$data = [
    'file_path' => 'languages/{LANGUAGE}.ini',
];
$configVo = new \Biniweb\I18n\Vo\I18nConfigVo($data);

$l = \Biniweb\I18n\I18n::getInstance()->init($configVo);

3. Use the localizations

example.php, (*8)

<p>A greeting: <?php echo $l['greeting']; ?> </p>
<p>Something other: <?php echo $l['category_somethingother']; ?> </p>

Mustache

2. Initialize the class with Mustache

example_mustache.php, (*9)

$data = [
    'file_path' => 'languages/{LANGUAGE}.ini',
];
$configVo = new \Biniweb\I18n\Vo\I18nConfigVo($data);

$l = \Biniweb\I18n\I18n::getInstance()->init($configVo);

$content = join('', file('example_mustache.html'));

$engine = new Mustache_Engine();

echo $engine->render($content, [
    'l' => $l,
]);

3. html template

example_mustache.html, (*10)

<p>A greeting: {{#l}} {{greeting}} {{/l}}</p>
<p>Something other: {{#l}} {{category_somethingother}} {{/l}}</p>

The Versions

31/03 2014

dev-master

9999999-dev https://github.com/biniweb/php-i18n

Simple Component for internationalizing

  Sources   Download

MIT

The Requires

 

by Giuseppe Maniscalco

i18n