The Locale component
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
docs
src
tests
.gitattributes
.gitignore
.scrutinizer.yml
.travis.yml
LICENSE
README.md
composer.json
phpunit.xml.dist

README.md

Locale

Build Status Code Coverage Scrutinizer Code Quality SensioLabsInsight

The Locale Component.

Example

<?php

use miBadger\Locale;

/**
 * Initialize the locales.
 * This uses the directory 'locale' to look for the translation files, and the 'messages' text domain.
 * Make sure the correct folders and MO files are created! See below for more information.
 */
Locale::init(__DIR__ . '/locale', 'messages');

/**
 * Add the different available locales.
 */
Locale::add('nl', 'nl_NL.UTF-8');
Locale::add('de', 'de_DE.UTF-8');

/**
 * Choose what locale you want to use.
 */
Locale::set('nl');

/**
 * Now you can use gettext, which should return the translated strings (if present in the MO files).
 * It is also possible to call another set() function to chance locale.
 */

Translation files

Given the example above, the following files should be present:

locale/
	nl_NL/
		LC_MESSAGES/
			messages.mo
	de_DE/
		LC_MESSAGES/
			messages.mo

The locale directory is set in the Locale::init function. The second parameter is the text domain (for our purposes, the name of the MO files).