kopfwelt / i18next-php
There is no license information available for the latest version (dev-master) of this package.
PHP class for basic i18next functionality.
dev-master
2015-12-05 21:46 UTC
Requires
- php: >=5.3.0
Requires (Dev)
- phpunit/phpunit: ~4.4
This package is not auto-updated.
Last update: 2025-02-19 21:49:13 UTC
README
PHP class for basic i18next functionality.
Features
- Support for variables
- Support for context
- Support for basic sprintf
- Support for basic plural forms
- Support for multiline in JSON
Usage
// init i18next instance i18next::init('en'); // get translation by key echo i18next::getTranslation('common.dog');
Methods
i18next::init( string $languageKey [, string $path ] );
Loads translation files from given path. Looks for translation.json
by default.
i18next::init('en', 'my/path/'); // loads my/path/translation.json
You can also use variables and split namespaces and languages to different files.
i18next::init('en', 'languages/__lng__/__ns__.json'); // loads languages/en/common.json, languages/fi/common.json, etc...
Method throws an exception if no files are found or the json can not be parsed.
mixed i18next::getTranslation( string $key [, array $variables ] );
Returns translated string by key.
i18next::getTranslation('common.cat', array('count' => 2, 'lng' => 'fi'));
boolean i18next::existTranslation( string $key );
Checks if translated string exists.
void i18next::setLanguage( string $language [, string $fallback ] );
Changes language.
array i18next::getMissingTranslations();
Gets an array of missing translations.
array(1) {
[0]=> array(2) {
["language"]=> string(2) "en"
["key"]=> string(14) "common.unknown"
}
}
Multilines in JSON-arrays
You can have html content written with multilines in JSON File
{
"en": {
"common": {
"thedoglovers":["The Dog Lovers by Spike Milligan",
"So they bought you",
"And kept you in a",
"Very good home"]
}
}
}