mvaliolahi / translator
There is no license information available for the latest version (dev-master) of this package.
Another library to achieve translation in your beautiful application!
dev-master
2017-11-21 15:04 UTC
Requires (Dev)
- phpunit/phpunit: ^6.2
This package is auto-updated.
Last update: 2024-11-10 00:58:59 UTC
README
Translate messages for any project.
Install
`composer require mvaliolahi/translator`
Usage
Make a directory as resources path, inside the ResourcePath directory make several directory for different languages.
example:
-
Resources/lang/en
. -
Inside
en
make a message.php file. -
The message.php is like below code:
<?php return [ 'test' => 'Test', ];
-
Finally instantiate Validator like below:
$translator = new Translator([ 'locale' => en', 'resourcePath' => __DIR__ . '/../src/Resources/lang' ]);
-
Use
of
method to find translation in specified language.$result = $translator->of('messages.test'); Output: Test $result = $translator->of('test'); Output: Test
Tips: The messages.php is default translation file, you could define another files as you wish!