tigron / skeleton-i18n
Translation and internationalization for Skeleton
Installs: 16 610
Dependents: 1
Suggesters: 1
Security: 0
Stars: 0
Watchers: 6
Forks: 1
Open Issues: 2
Requires
- dev-master
- v4.0.7
- v4.0.6
- v4.0.5
- v4.0.4
- v4.0.3
- v4.0.2
- v4.0.1
- v4.0.0
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- 2.1.12
- v2.1.11
- v2.1.10
- v2.1.9
- v2.1.8
- v2.1.7
- v2.1.6
- v2.1.5
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0
- 1.x-dev
- v1.0.18
- v1.0.17
- v1.0.16
- v1.0.15
- v1.0.14
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v0.0.9
- v0.0.8
- v0.0.7
- v0.0.6
- v0.0.5
- v0.0.4
- v0.0.3
- v0.0.2
- v0.0.1
- v0
This package is auto-updated.
Last update: 2024-12-16 11:57:12 UTC
README
Description
This library enables internationalization and translation features in Skeleton.
Installation
Installation via composer:
composer require tigron/skeleton-i18n
Run the migrations to update the database schema:
skeleton migrate:up
Howto
Translate a Skeleton App:
/**
* Create a translator object
*/
$translator = new \Skeleton\I18n\Translator($application->name);
/**
* Attach a storage
*/
$translator_storage_po = new \Skeleton\I18n\Translator\Storage\Po();
$translator_storage_po->set_configuration([
'storage_path' => $root_path . '/po/'
]);
$translator->set_translator_storage($translator_storage_po);
/**
* Use an extractor to extract translations from templates
*/
$translator_extractor_twig = new \Skeleton\I18n\Translator\Extractor\Twig();
$translator_extractor_twig->set_template_path($application->template_path);
$translator->set_translator_extractor($translator_extractor_twig);
/**
* Save the translator
*/
$translator->save();
/**
* To translate, get the translation object and ask for a translation
*/
$translation = $translator->get_translation( Language::get_by_name_short('nl') );
echo $translation->translate('This is a test');
Translator\Storage objects can have a default configuration. This configuration will be used for any newly created Translator\Storage object.
\Skeleton\I18n\Translator\Storage\Po::set_default_configuration([
'storage_path' => $root_path . '/po/'
]);
/**
* Optional:
* Set another Language interface
*/
\Skeleton\I18n\Config::$language_interface = '\Language';
Use it:
Via a twig template rendered by skeleton-template-twig:
{% trans "To be translated" %}