Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tacoberu/nette-fluent-translator
Nette adapter for PHP implementation of Project Fluent.
https://github.com/tacoberu/nette-fluent-translator
Last synced: 2 months ago
JSON representation
Nette adapter for PHP implementation of Project Fluent.
- Host: GitHub
- URL: https://github.com/tacoberu/nette-fluent-translator
- Owner: tacoberu
- License: mit
- Created: 2020-02-27T01:17:53.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-21T02:25:48.000Z (almost 2 years ago)
- Last Synced: 2024-10-09T20:44:34.368Z (2 months ago)
- Language: PHP
- Size: 15.6 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Nette adapter for Fluent localization
=====================================This is a Nette adapter for PHP implementation of Project Fluent, a localization framework
designed to unleash the entire expressive power of natural language
translations.Project Fluent keeps simple things simple and makes complex things possible.
The syntax used for describing translations is easy to read and understand. At
the same time it allows, when necessary, to represent complex concepts from
natural languages like gender, plurals, conjugations, and others.Learn the FTL syntax
--------------------FTL is a localization file format used for describing translation resources.
FTL stands for _Fluent Translation List_.FTL is designed to be simple to read, but at the same time allows to represent
complex concepts from natural languages like gender, plurals, conjugations, and
others.hello-user = Hello, { $username }!
[Read the Fluent Syntax Guide][] in order to learn more about the syntax. If
you're a tool author you may be interested in the formal [EBNF grammar][].[Read the Fluent Syntax Guide]: http://projectfluent.org/fluent/guide/
[EBNF grammar]: https://github.com/projectfluent/fluent/tree/master/specInstallation
------------The recommended way to install is via Composer:
composer require tacoberu/nette-fluent-translator
Usage
-----Sample flt localation file
```ini-brand-name = Foo 3000
welcome = Welcome, {$name}, to {-brand-name}!
greet-by-name = Hello, { $name }!
form-title = Title
```neon configuration
```iniextensions:
translation: Taco\NetteFluentTranslator\Extension(%appDir%/locales)translation:
defaultLocale: cs_CZ
supportedLocales:
- cs_CZ
- fr_FR
- en_GB
```In php code:
```php$translator = $container->getService('translator');
dump($translator->translate('-brand-name'));
// "Foo 3000"dump($translator->translate('welcome', ['name' => 'Anne']));
// "Welcome, Anne, to Foo 3000!"dump($translator->translate('greet-by-name', ['name' => 'Anne']));
// "Hello, Anne!"This means, for example:
```php
function beforeRender()
{
$this->template->setTranslator($this->context->getByType(Nette\Localization\ITranslator::class));
}
```
and```php
$form = new UI\Form($this, $name);
$form->setTranslator($this->context->getByType(Localization\ITranslator::class));
$form->addText('title', 'form-title');
```In Latte template:
```html
{_"-brand-name"}
{_"welcome", ["name" => "Anne"]}
{_"greet-by-name", ["name" => "Anne"]}
```