2017 © Pedro Peláez
 

library locale

library for working with different languages

image

fdevs/locale

library for working with different languages

  • Saturday, August 13, 2016
  • by andrey1s
  • Repository
  • 3 Watchers
  • 0 Stars
  • 262 Installations
  • PHP
  • 4 Dependents
  • 1 Suggesters
  • 1 Forks
  • 0 Open issues
  • 12 Versions
  • 0 % Grown

The README.md

Locale Library

Build Status, (*1)

SensioLabsInsight, (*2)

Documentation

Installation and usage

Installation and usage is a quick:, (*3)

  1. Download Locale using composer
  2. Use the library
  3. Customize Data Provider

You can "fdevs/locale-bridge" for use with other libraries/components, (*4)

Step 1: Download Locale library using composer

Download the bundle by running the command:, (*5)

``` bash $ php composer.phar require fdevs/locale, (*6)


Composer will install the bundle to your project's `vendor/fdevs` directory. ### Step 2: Use the library ####Basic setup: ```php <?php require DIR . '/../vendor/autoload.php'; use FDevs\Locale\Model\LocaleText; use FDevs\Locale\Translator; // The same text in different languages $englishText = new LocaleText('I am a programmer', 'en'); $chineseText = new LocaleText('我是程序员', 'zh'); $russianText = new LocaleText('Я программист', 'ru'); $supportedTexts = [ $englishText, $russianText, $chineseText, ]; $trans = new Translator();

Set current locale:

$trans->setLocale('zh');

Get text for current locale:

// 1. Get text for current locale - ch (Chinese)
$text = $trans->trans($supportedTexts);
echo $text?$text->getText():'';
// Output: "我是程序员"

Get text for locale - ru:

$text = $trans->trans($supportedTexts, 'ru');
echo $text?$text->getText():'';
// Output: "Я программист"

Get text for a locale for which we don't have translation:

$text = $trans->trans($supportedTexts, 'kk');
echo $text?$text->getText():'';
// Output: ""

Get text using a set of prioritized locales:

Here you can treat this as locales fallback, first found locale from your list will be chosen., (*7)

use FDevs\Locale\Model\PriorityLocale;
use FDevs\Locale\TranslatorPriority;

$priorityLocale = [
    new PriorityLocale('uk',['en','ru']),
    new PriorityLocale('en',['uk']),
    new PriorityLocale('fa',['zh','en']),
];

$trans = new TranslatorPriority('en',$priorityLocale);
$text = $trans->trans($supportedTexts, 'uk');
echo $text?$text->getText():'';
// Output: "I am programmer"

Step 3: Customize Data Provider

create your awesome provider

use FDevs\Locale\DataProvider\DataProviderInterface;

class MyProvider implements DataProviderInterface
{
//implement interface
}

add your provider

use FDevs\Locale\DataProvider\DataProviderRegistry;
use FDevs\Locale\Translator;
use FDevs\Locale\TranslatorPriority;

$registry = new DataProviderRegistry([new MyProvider()]);
$translator = new Translator('en',$registry);
//or
$translator = new TranslatorPriority('en', $priorityLocale, $registry);

License

This library is under the MIT license. See the complete license in the Library:, (*8)

LICENSE

Reporting an issue or a feature request

Issues and feature requests are tracked in the Github issue tracker., (*9)

The Versions

13/08 2016

2.0.x-dev

2.0.9999999.9999999-dev https://github.com/4devs/Locale

library for working with different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

locale languages

13/08 2016

2.4.1

2.4.1.0 https://github.com/4devs/Locale

library for working with different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

locale languages

13/08 2016

2.4.0

2.4.0.0 https://github.com/4devs/Locale

library for working with different languages

  Sources   Download

MIT

The Requires

 

The Development Requires

locale languages

05/05 2016

dev-master

9999999-dev https://github.com/4devs/Locale

library for working with different languages

  Sources   Download

MIT

The Requires

 

locale languages

05/02 2016

3.0.x-dev

3.0.9999999.9999999-dev https://github.com/4devs/Locale

library for working with different languages

  Sources   Download

MIT

The Requires

 

locale languages

05/02 2016

3.0.0

3.0.0.0 https://github.com/4devs/Locale

library for working with different languages

  Sources   Download

MIT

The Requires

 

locale languages

11/09 2015

2.3.0

2.3.0.0 https://github.com/4devs/Locale

library for working with different languages

  Sources   Download

MIT

The Requires

 

locale languages

25/06 2015

2.2.0

2.2.0.0 https://github.com/4devs/Locale

library for working with different languages

  Sources   Download

MIT

The Requires

 

locale languages

11/06 2015

2.1.0

2.1.0.0 https://github.com/4devs/Locale

library for working with different languages

  Sources   Download

MIT

The Requires

 

locale languages

07/06 2015

2.0.0

2.0.0.0 https://github.com/4devs/Locale

library for working with different languages

  Sources   Download

MIT

The Requires

 

locale languages

12/03 2015

v1.1.0

1.1.0.0 https://github.com/4devs/Locale

library for working with different languages

  Sources   Download

MIT

The Requires

 

locale languages

03/02 2015

v1.0.0

1.0.0.0 https://github.com/4devs/Locale

library for working with different languages

  Sources   Download

MIT

The Requires

 

locale languages