https://github.com/chubbyphp-legacy/chubbyphp-translation
A simple translation solution.
https://github.com/chubbyphp-legacy/chubbyphp-translation
Last synced: 6 months ago
JSON representation
A simple translation solution.
- Host: GitHub
- URL: https://github.com/chubbyphp-legacy/chubbyphp-translation
- Owner: chubbyphp-legacy
- License: mit
- Archived: true
- Created: 2016-10-02T11:16:30.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2018-12-07T06:37:45.000Z (over 7 years ago)
- Last Synced: 2025-11-27T14:48:59.595Z (7 months ago)
- Language: PHP
- Size: 21.5 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# chubbyphp-translation
[](https://travis-ci.org/chubbyphp/chubbyphp-translation)
[](https://scrutinizer-ci.com/g/chubbyphp/chubbyphp-translation/?branch=master)
[](https://scrutinizer-ci.com/g/chubbyphp/chubbyphp-translation/?branch=master)
[](https://packagist.org/packages/chubbyphp/chubbyphp-translation)
[](https://packagist.org/packages/chubbyphp/chubbyphp-translation)
[](https://packagist.org/packages/chubbyphp/chubbyphp-translation)
[](https://packagist.org/packages/chubbyphp/chubbyphp-translation)
## Description
A simple translation solution.
## Requirements
* php: ~7.0
## Suggest
* pimple/pimple: ~3.0
* twig/twig: ^1.25.0
## Installation
Through [Composer](http://getcomposer.org) as [chubbyphp/chubbyphp-translation][1].
```sh
composer require chubbyphp/chubbyphp-translation "~1.1"
```
## Usage
### Translator
```php
'erfolgreiche Uebersetzung',
'another.existing.key' => '%d erfolgreiche Uebersetzungen',
'yetanother.existing.key' => '{{key}} erfolgreiche Uebersetzungen'
]),
new LocaleTranslationProvider('en', [
'some.existing.key' => 'successful translation',
'another.existing.key' => '%d successful translations'
'yetanother.existing.key' => '{{key}} successful translations'
])
]);
echo $translator->translate('de', 'some.existing.key'); // erfolgreiche Uebersetzung
echo $translator->translate('en', 'some.existing.key'); // successful translation
echo $translator->translate('fr', 'some.existing.key'); // some.existing.key
echo $translator->translate('de', 'another.existing.key', [5]); // 5 erfolgreiche Uebersetzungen
echo $translator->translate('en', 'another.existing.key', [5]); // 5 successful translations
echo $translator->translate('fr', 'another.existing.key', [5]); // some.existing.key
echo $translator->translate('de', 'yetanother.existing.key', ['key' => 5]); // 5 erfolgreiche Uebersetzungen
echo $translator->translate('en', 'yetanother.existing.key', ['key' => 5]); // 5 successful translations
echo $translator->translate('fr', 'yetanother.existing.key', ['key' => 5]); // some.existing.key
```
### TranslationProvider (Pimple)
```php
register(new TranslationProvider);
$container->extend('translator.providers', function (array $providers) use ($container) {
$providers[] = new LocaleTranslationProvider('de', [
'some.existing.key' => 'erfolgreiche Uebersetzung',
'another.existing.key' => '%d erfolgreiche Uebersetzungen'
]);
$providers[] = new LocaleTranslationProvider('en', [
'some.existing.key' => 'successful translation',
'another.existing.key' => '%d successful translations'
]);
return $providers;
});
/** @var Translation $translator */
$translator = $container['translator'];
```
### TranslationTwigExtension
```php
addExtension(new TranslationTwigExtension(new Translator([])));
```
```twig
{{ 'some.existing.key'|translate('de') }}
{{ 'another.existing.key'|translate('de', [5]) }}
{{ 'yetanother.existing.key'|translate('de', ['key' => 5]) }}
```
[1]: https://packagist.org/packages/chubbyphp/chubbyphp-translation
## Copyright
Dominik Zogg 2016