Basic Usage

  1. place your locale files into a folder of your choice using xx_YY.php for the naming convention. For example, en_CA.php or en_US.php

  2. all your locale files should be in the same folder.

  3. when defining your strings, you can use an array. The first element is the singular version. The second is the plural version.

<?php
/* en_CA.php */
return [
    'TEXT_HOME'=>'Home',
    'TEXT_APPLE'=>['apple', 'apples'] // singlular and plural version of the word
];

/* fr_CA.php */
return [
    'TEXT_HOME'=>'Accueil',
    'TEXT_APPLE'=>['pomme', 'pommes']
];

Now, instantiate the Vespula\Locale\Locale object and load the locales. Then, you are ready to display localized strings based on a key.

<?php
$locale = new \Vespula\Locale\Locale('en_CA');
$locale->load('/path/to/locales');

// show all the strings for each language code
print_r($locale->getStrings());

// Get a single string
echo $locale->gettext('TEXT_HOME');

// Get a pluralized form of the string
// The second parameter is the number of objects you have.
echo $locale->gettext('TEXT_APPLE', 4);
// displays 'apples'

// switch langs
$locale->setCode('fr_CA');
echo $locale->gettext('TEXT_APPLE', 4);
// displays 'pommes'