2017 © Pedro Peláez
 

library i18n

Internationalization and string translation package Slick Framework

image

slick/i18n

Internationalization and string translation package Slick Framework

  • Monday, November 20, 2017
  • by fsilva
  • Repository
  • 2 Watchers
  • 0 Stars
  • 928 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

Slick I18n package

Latest Version on Packagist ![Software License][ico-license] Build Status Quality Score ![Total Downloads][ico-downloads], (*1)

Slick I18n is a simple translation and internationalization package. It depends on Zend/I18n which is a complete translation suite that supports all major formats and includes popular features like plural translations and text domains., (*2)

This package is compliant with PSR-2 code standards and PSR-4 autoload standards. It also applies the semantic version 2.0.0 specification., (*3)

Install

Via Composer, (*4)

``` bash $ composer require slick/i18n, (*5)


## Usage ### Messages file Create a messages file: ```php /** * pt_PT messages file */ return [ '' => array( 'plural_forms' => 'nplurals=2; plural=n!=1;' ), 'Hello world' => 'Olá mundo', 'User' => ['Utilizador', 'Utilizadores'], 'Users' => '' ];

save this file in ./i18n/pt_PT/messages.php., (*6)

Language negotiation and setup

Now lets get our translator:, (*7)


use Slick\I18n\Language; use Slick\I18n\Translation; use Slick\I18n\Translator; /** * Set locale based on the browser accept language */ $locale = 'en_US'; if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $locale = \Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']); } $translation = new Translation(new Language($locale), __DIR__.'/i18n'); $translator = new Translator($translation); setlocale(LC_ALL, $locale);

The code above is using the browser's language to set the locale for our translator object. From now on just use the translation methods on the strings you want to translate., (*8)

Message translation

echo $translator->translate('Hello world');  // will output 'Olá mundo' 

Plural translation

echo $translator->translatePlural('User', 'Users', 2);  // will output 'Utilizadores' 

Using in your classes

You can add translation functionality to your classes by using the TranslateMethods trait and injecting the translator., (*9)

use Slick\I18n\TranslateMethods;
use Slick\I18n\TranslationCapableInterface;
use Slick\I18n\TranslatotInterface;

class MyClass implements TranslationCapableInterface
{

    use TranslateMethods;

    public function __construct(TranslatotInterface $translator)
    {
        $this->tranlator = $translator;
    }  

    public function getUsers()
    {
        return $this->translatePlural('User', 'Users', $this->getUserCount());
    }
}

Change log

Please see CHANGELOG for more information on what has changed recently., (*10)

Testing

bash $ composer test, (*11)

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details., (*12)

Security

If you discover any security related issues, please email slick.framework@gmail.com instead of using the issue tracker., (*13)

Credits

License

The MIT License (MIT). Please see License File for more information., (*14)

The Versions

20/11 2017

dev-develop

dev-develop https://github.com/slickframework/tempalte

Internationalization and string translation package Slick Framework

  Sources   Download

MIT

The Requires

 

The Development Requires

translation i18n slick

20/11 2017

dev-master

9999999-dev https://github.com/slickframework/tempalte

Internationalization and string translation package Slick Framework

  Sources   Download

MIT

The Requires

 

The Development Requires

translation i18n slick

20/11 2017
20/11 2017
22/02 2016

v1.2.0

1.2.0.0 https://github.com/slickframework/tempalte

Internationalization and string translation package Slick Framework

  Sources   Download

MIT

The Requires

 

The Development Requires

translation i18n slick