2017 © Pedro Peláez
 

library localization

Php localization

image

mhndev/localization

Php localization

  • Monday, October 30, 2017
  • by majidphpdeveloper
  • Repository
  • 2 Watchers
  • 1 Stars
  • 233 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 13 Versions
  • 0 % Grown

The README.md

Build Status Latest Stable Version Latest Unstable Version License composer.lock available, (*1)

Localization i18n

sample code


use mhndev\localization\LanguageFactory; use mhndev\localization\LanguageLoader; use mhndev\localization\repositories\PhpArray; use mhndev\localization\Translator; ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); include_once 'vendor/autoload.php'; $repository = new PhpArray(getcwd().DIRECTORY_SEPARATOR.'en.php'); $lang_en = LanguageFactory::fromCountryCode('us')->setRepository($repository); $repository = new PhpArray(getcwd().DIRECTORY_SEPARATOR.'fa.php'); $lang_fa = LanguageFactory::fromUrlCode('fa')->setRepository($repository); $translator = new Translator(); $translator->addLanguage($lang_en); $translator->addLanguage($lang_fa); $params = [ 'name' => 'مجید', 'job' => 'برنامه نویس', 'company' => 'دیجی پیک' ]; $result = $translator->translate( 'greet', LanguageFactory::fromUrlCode('fa'), $params ); var_dump($result); /* * output would be : * * today is پنجشنبه ۲۴ فروردین ۱۳۹۶ - ۱۰:۵۶ and yesterday was :چهارشنبه ۲۳ فروردین ۱۳۹۶ - ۱۰:۵۶ * * سلام من مجید هستم . من یک برنامه نویس هستم و در شرکت دیجی پیک کار میکنم */ echo '
'.$result.'
'; date_default_timezone_set('Asia/Tehran'); $now = time(); $yesterday = $now - 3600 * 24; $string = 'today is {{'.$now.'|date }} and yesterday was :{{'.$yesterday.'| date}}'; /* * output would be : * * today is پنجشنبه ۲۴ فروردین ۱۳۹۶ - ۱۰:۵۶ and yesterday was :چهارشنبه ۲۳ فروردین ۱۳۹۶ - ۱۰:۵۶ */ $translation = $translator->localizeText($string, LanguageFactory::fromUrlCode('fa')); echo '<br>'; echo $translation; $lngLoader = new LanguageLoader(); $language = LanguageFactory::fromUrlCode('en'); $languageDetector = new \mhndev\localization\LanguageDetector(); $languageDetector->registerStrategy(new \mhndev\localization\strategies\StrategyUriChunk()); $languageDetector->registerStrategy(new \mhndev\localization\strategies\StrategyQueryParameter()); $languageDetector->registerStrategy(new \mhndev\localization\strategies\StrategyAcceptLngHeader()); $request = \GuzzleHttp\Psr7\ServerRequest::fromGlobals()->withUri(new \GuzzleHttp\Psr7\Uri( 'http://example.com/fa/some/random/address?key=value' )); $result = $languageDetector->detect($request); var_dump($result); die();

The Versions

30/10 2017

dev-master

9999999-dev http://github.com/mhndev/localization

Php localization

  Sources   Download

MIT

The Requires

 

The Development Requires

language i18n localization

30/10 2017

1.3.4

1.3.4.0 http://github.com/mhndev/localization

Php localization

  Sources   Download

MIT

The Requires

 

The Development Requires

language i18n localization

21/06 2017

dev-develop

dev-develop http://github.com/mhndev/localization

Php localization

  Sources   Download

MIT

The Requires

 

The Development Requires

language i18n localization

21/06 2017

1.3.3

1.3.3.0 http://github.com/mhndev/localization

Php localization

  Sources   Download

MIT

The Requires

 

The Development Requires

language i18n localization

21/06 2017

dev-hotFix

dev-hotFix http://github.com/mhndev/localization

Php localization

  Sources   Download

MIT

The Requires

 

The Development Requires

language i18n localization

29/04 2017

1.3.2

1.3.2.0 http://github.com/mhndev/localization

Php localization

  Sources   Download

MIT

The Requires

 

The Development Requires

language i18n localization

24/04 2017

1.3.1

1.3.1.0 http://github.com/mhndev/localization

Php localization

  Sources   Download

MIT

The Requires

 

The Development Requires

language i18n localization

23/04 2017

1.3.0

1.3.0.0 http://github.com/mhndev/localization

Php localization

  Sources   Download

MIT

The Requires

 

The Development Requires

language i18n localization

23/04 2017

1.2.0

1.2.0.0 http://github.com/mhndev/localization

Php localization

  Sources   Download

MIT

The Requires

 

The Development Requires

language i18n localization

23/04 2017

1.1.2

1.1.2.0 http://github.com/mhndev/localization

Php localization

  Sources   Download

MIT

The Requires

 

The Development Requires

language i18n localization

23/04 2017

1.1.1

1.1.1.0 http://github.com/mhndev/localization

Php localization

  Sources   Download

MIT

The Requires

 

The Development Requires

language i18n localization

18/04 2017

1.1.0

1.1.0.0 http://github.com/mhndev/localization

Php localization

  Sources   Download

MIT

The Requires

 

The Development Requires

language i18n localization

12/04 2017

1.0.0

1.0.0.0 http://github.com/mhndev/localization

Php localization

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

language i18n localization