undercloud / lang
PHP Multilanguage System
dev-master
2016-04-13 19:37 UTC
Requires
- php: >=5.3.0
This package is auto-updated.
Last update: 2024-12-28 07:45:38 UTC
README
#Lang PHP Multilanguage System
##install
composer require undercloud/lang
##translates
// /en/message.php return [ 'hello' => 'Hello, :username', 'hobbies' => 'Your hobbies is: :hobbies' ];
##setup
require 'vendor/autoload.php'; $lang = new Undercloud\Lang([ // translates path 'root' => '/path/to/translates', // list of user accepted, default parse http header Accept-Language 'accept' => ['en', 'de'], // list of supported translates 'avail' => ['en','fr','de'], // setup translates file handler, default PHP Arrays 'parser' => new Undercloud\Lang\Parser\AbstractParser ]); // Hello, John $lang('message.hello', ['username' => 'John']); //Your hobbies is: music, football, web $lang('message.hobbies', ['hobbies': ['music', 'football', 'web']]);
##api
// parse Accept-Language header and return supported locales $lang->getLangsHttp(); // return primary locale name $lang->getPrimaryLocale(); // return fallback locale $lang->getFallBackLocale();
##parser
By default avail two type of language files parsers Undercloud\Lang\Parser\DefaultParser
and Undercloud\Lang\Parser\JsonParser
,
You can define you'r own parser:
// file based parser use Undercloud\Lang\Parser\AbstractParser; class MyOwnParser extends AbstractParser { public function parse() { $path = func_get_arg(0) . '.extension'; /*...*/ } }
or
// database like parser use Undercloud\Lang\Parser\AbstractParser; class MyOwnParser extends AbstractParser { public $buildPath = false; public function parse() { $locale = func_get_arg(0); $entity = func_get_arg(1); /*...*/ } }