2017 © Pedro Peláez
 

library translate

Easy to use i18n translation PHP class for multi-language websites

image

delfimov/translate

Easy to use i18n translation PHP class for multi-language websites

  • Monday, November 13, 2017
  • by elfimov
  • Repository
  • 2 Watchers
  • 5 Stars
  • 314 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 10 Versions
  • 26 % Grown

The README.md

Latest Stable Version Build Status StyleCI SensioLabsInsight License, (*1)

Translate

Easy to use i18n translation PHP class for multi-language websites with language auto detection and plurals., (*2)

PSR-6 translation containers. PSR-3 logger., (*3)

Requirements

How to install

Add this line to your composer.json file:, (*4)

"delfimov/translate": "~2.0"

or, (*5)

composer require delfimov/translate

Alternatively, copy the contents of the Translate folder into one of your project's directories and require 'src/Translate.php';, require 'src/Loader/LoaderInterface.php';, require 'src/Loader/PhpFilesLoader.php'; If you don't speak git or just want a tarball, click the 'zip' button at the top of the page in GitHub., (*6)

A Simple Example

See example directory for sources., (*7)

example\example.php, (*8)



pushHandler(new StreamHandler('path/to/your.log', Logger::WARNING));

$t = new Translate(
    new PhpFilesLoader(__DIR__ . "/messages"),
    [
        "default" => "en",
        "available" => ["en", "ru"],
    ],
    $log // optional
);

$num = rand(0, 100);

$t->setLanguage("en"); // this is not required, language will be auto detected with Accept-Language HTTP header
echo $t->t('some string') . "\n\n"; // or $t('some string');
echo $t->plural('%d liters', $num) . "\n\n";
echo $t->plural("The %s contains %d monkeys", $num, ['tree', $num]) . "\n\n";

$num = rand(0, 100);

$t->setLanguage("ru");
echo $t->t('some string')."\n\n"; // or $t('some string');
echo $t->plural('%d liters', $num) . "\n\n";
echo $t->plural("The %s contains %d monkeys", $num, ['tree', $num]) . "\n\n";

?>

example\messages\en\messages.php, (*9)

<?php
return [
    'some string' => 'Some string',
    '%d liters' => ['%d liter', '%d liters'],
    '%d liters alt' => '%d liter|%d liters',
    'The %s contains %d monkeys' => ['The %s contains %d monkey', 'The %s contains %d monkeys'],
    'The %s contains %d monkeys alt' => 'The %s contains %d monkey|The %s contains %d monkeys',
];

example\messages\ru\messages.php, (*10)

<?php
return [
    'some string' => 'Просто строка',
    '%d liters' => '%d литр|%d литра|%d литров',
    'The %s contains %d monkeys' => ['На %s сидит %d обезьяна', 'На %s сидят %d обезьяны', 'На %s сидят %d обезьян'],
    'The %s contains %d monkeys alt' => 'На %s сидит %d обезьяна|На %s сидят %d обезьяны|На %s сидят %d обезьян',
    'tree' => 'дереве'
];

TODO

  • Better code coverage

The Versions

13/11 2017

dev-master

9999999-dev https://github.com/delfimov/Translate/

Easy to use i18n translation PHP class for multi-language websites

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Dmitry Elfimov

language i18n translate plural multi-language

13/11 2017

v2.4.0

2.4.0.0 https://github.com/delfimov/Translate/

Easy to use i18n translation PHP class for multi-language websites

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Dmitry Elfimov

language i18n translate plural multi-language

15/08 2017

v2.3.2

2.3.2.0 https://github.com/delfimov/Translate/

Easy to use i18n translation PHP class for multi-language websites

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Dmitry Elfimov

language i18n translate plural multi-language

14/08 2017

v2.3.1

2.3.1.0 https://github.com/delfimov/Translate/

Easy to use i18n translation PHP class for multi-language websites

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Dmitry Elfimov

language i18n translate plural multi-language

19/07 2017

v2.2.1

2.2.1.0 https://github.com/delfimov/Translate/

Easy to use i18n translation PHP class for multi-language websites

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Dmitry Elfimov

language i18n translate plural multi-language

19/07 2017

v2.3.0

2.3.0.0 https://github.com/delfimov/Translate/

Easy to use i18n translation PHP class for multi-language websites

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Dmitry Elfimov

language i18n translate plural multi-language

18/07 2017

v2.2.0

2.2.0.0 https://github.com/delfimov/Translate/

Easy to use i18n translation PHP class for multi-language websites

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Dmitry Elfimov

language i18n translate plural multi-language

08/06 2017

v2.1.0

2.1.0.0 https://github.com/delfimov/Translate/

Easy to use translate library for multi-language websites

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Dmitry Elfimov

language translate plural multi-language

08/06 2017

v2.0

2.0.0.0 https://github.com/delfimov/Translate/

Easy to use translate library for multi-language websites

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Dmitry Elfimov

language translate plural multi-language

08/06 2017

v2.0.1

2.0.1.0 https://github.com/delfimov/Translate/

Easy to use translate library for multi-language websites

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Dmitry Elfimov

language translate plural multi-language