PHP code example of webiik / translation
1. Go to this page and download the library: Download webiik/translation library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
webiik / translation example snippets
$translation = new \Webiik\Translation\Translation($arr);
$translation->setLang('en');
$translation->add('greeting', 'Hello {name}!');
echo $translation->get('greeting', ['name' => 'Kitty']);
$translation->setLang('cs');
$translation->add('greeting', 'Ahoj {name}!');
echo $translation->get('greeting', ['name' => 'Kitty']);
setLang(string $lang): void
$translation->setLang('en');
inject(string $parserClassName, TranslationInjector $injector): void
$translation->inject('Route', new \Webiik\Translation\TranslationInjector(function () use (&$router) {
return [$router];
}));
add(string $key, string $val): void
$translation->add('greeting', 'Hello {name}!');
addArr(array $translation, &$context = false): void
$translation->addArr(['greeting' => 'Hello {name}!']);
get(string $key, array|bool|null $parse = null): string|array
$translation->get('greeting', ['name' => 'Kitty']);
getAll(array|bool|null $parse = null): array
$translation->getAll(['name' => 'Kitty']);
getMissing(): array
$missing = $translation->$arr->getMissing();
$translation->add('greeting', 'Hello {name}!');
echo $translation->get('greeting', ['name' => 'Kitty']);
// Hello Kitty!
$translation->add('cats', '{numCats, Plural, {0- No cats.} {1 One cat.} {2+ {numCats} cats.}}');
echo $translation->get('cats', ['numCats' => 2]);
// 2 cats.
$translation->add('hello-cat', '{gender, Select, {male Hello Tom!} {female Hello Kitty!}}');
echo $translation->get('hello-cat', ['gender' => 'male']);
// Hello Tom!
$translation->add('link', 'Visit the {Link, {official page} {https://www.webiik.com} {_blank} {nofollow}}.');
echo $translation->get('link', true);
// Visit the <a href="https://www.webiik.com" target="_blank" rel="nofollow">official website</a>.