From cefce0de07413f29d4b6512c0dca46fb64c2a041 Mon Sep 17 00:00:00 2001 From: Martin Zeman Date: Thu, 26 Mar 2015 23:55:36 +0100 Subject: [PATCH] Update README.md --- README.md | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/README.md b/README.md index c8442ee..4b3c28c 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,98 @@ Localization, plurals and translator ## About l10n is a package combining many languages from [ISO 639-1](http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (112/185), all Plurals from [Mozilla Developer Network](https://developer.mozilla.org/en-US/docs/Mozilla/Localization/Localization_and_Plurals) and simple translator. + +## Packagist +l10n is available on [Packagist.org](https://packagist.org/packages/zemistr/l10n), +just add the dependency to your composer.json. + +```javascript +{ + "require" : { + "zemistr/l10n": "1.*" + } +} +``` + +or run Composer command: +```php +php composer.phar require zemistr/l10n +``` + +## Usage without composer + +```php +setText($key, $text, $plural = 0); +$translator->setText('statistics.users', '%n% person'); // 0 or nothing for singular +$translator->setText('statistics.users', '%n% people', 1); + +// get translations +// $translator->translate($key, $n = 1, array $parameters = array()); +// +// or for singular +// $translator->translate($key, array $parameters = array()); +echo $translator->translate('statistics.users', 0) . '
'; // 0 people +echo $translator->translate('statistics.users', 1) . '
'; // 1 person +echo $translator->translate('statistics.users', 50) . '
'; // 50 people +echo $translator->translate('statistics.users', 100) . '
'; // 100 people + +// we can use %variables% in translations +// in default is available variable %n% for number $n (singular/plural number) + +$translator->setText('user', 'I am %firstname% %lastname%'); + +echo $translator->translate('user', ['%firstname%' => 'John', '%lastname%' => 'Doe']); // I am John Doe +``` + +## Basic translator usage with Language + +```php +setText($key, $text, $plural = 0); +$translator->setText('statistics.users', '%n% person'); // 0 or nothing for singular +$translator->setText('statistics.users', '%n% people', 1); + +// get translations +// $translator->translate($key, $n = 1, array $parameters = array()); +// +// or for singular +// $translator->translate($key, array $parameters = array()); +echo $translator->translate('statistics.users', 0) . '
'; // 0 people +echo $translator->translate('statistics.users', 1) . '
'; // 1 person +echo $translator->translate('statistics.users', 50) . '
'; // 50 people +echo $translator->translate('statistics.users', 100) . '
'; // 100 people + +// we can use %variables% in translations +// in default is available variable %n% for number $n (singular/plural number) + +$translator->setText('user', 'I am %firstname% %lastname%'); + +echo $translator->translate('user', ['%firstname%' => 'John', '%lastname%' => 'Doe']); // I am John Doe +``` + + +----- + +(c) Martin Zeman (Zemistr), 2015 (http://zemistr.eu)