0.1 2017-02-03 03:32 UTC


Charcoal provides a comprehensive solution for handling localisation, internationalization, and translation for a multi-lingual Charcoal project.


Setting the default language / setting the current language:

use \Charcoal\Translation\TranslationConfig;

$translation_config = TranslationConfig::instance();

// Set the list of available languages
    'en' => [],
    'fr' => []

// Set the default language to "English" ("en")

// Set the current language to French

Loading a (translated) string from the catalog:

use \Charcoal\Translation\Catalog;

$catalog = Catalog::instance();
echo $catalog->tr('my string');

// Add a custom string..
$catalog->add_translation('custom string', [
    'en' => 'Custom string',
    'fr' => 'Chaîne aléatoire'
ech $catalog->tr('custom string');

Using the TranslationString object directly:

// Let's assume the default language has been set to 'en'...

use \Charcoal\Translation\TranslationString;

$str = new TranslationString([
    'fr' => 'foo',
    'en' => 'bar'

// All the following examples output "bar"
echo $str;
echo $str->en();
echo $str->val('en');

// All the following examples output "foo"
echo $str->fr();
echo $str->set_lang('fr')->val();
echo $str->val('fr');

With Mustache Templates

By default, all call to the {{# _t }} mustache helper in Charcoal Templates will try to translate a string using the default Charcoal Catalog.

For example:

  • Assuming the "my string" has been added to the main catalog, as in the previous example


  • Charcoal\Config required by TranslationConfig