2017 © Pedro PelĂĄez
 

library charcoal-translation

Charcoal Translations & Languages

image

locomotivemtl/charcoal-translation

Charcoal Translations & Languages

  • Friday, March 10, 2017
  • by mducharme
  • Repository
  • 8 Watchers
  • 0 Stars
  • 5,878 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Charcoal Translation

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

Usage

Setting the default language / setting the current language:, (*2)

use \Charcoal\Translation\TranslationConfig;

$translation_config = TranslationConfig::instance();

// Set the list of available languages
$translation_config->set_available_langs([
    'en' => [],
    'fr' => []
]);

// Set the default language to "English" ("en")
$translation_config->set_default_lang('en');

// Set the current language to French
$translation_config->set_lang('fr');

Loading a (translated) string from the catalog:, (*3)

use \Charcoal\Translation\Catalog;

$catalog = Catalog::instance();
$catalog->add_resource('myproject.csv');
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:, (*4)

// 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., (*5)

For example:, (*6)

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

Dependencies

  • Charcoal\Config required by TranslationConfig

The Versions

13/10 2016

dev-mcaskill-symfony

dev-mcaskill-symfony https://charcoal.locomotive.ca

Provides tools to internationalize Charcoal.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mathieu Ducharme

translation i18n l10n charcoal