Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mika-/i18next-php
PHP class for basic i18next functionality
https://github.com/mika-/i18next-php
i18n i18next php54
Last synced: about 11 hours ago
JSON representation
PHP class for basic i18next functionality
- Host: GitHub
- URL: https://github.com/mika-/i18next-php
- Owner: Mika-
- Created: 2014-01-10T18:09:22.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2021-06-03T14:28:28.000Z (over 3 years ago)
- Last Synced: 2024-09-24T19:59:01.567Z (about 13 hours ago)
- Topics: i18n, i18next, php54
- Language: PHP
- Homepage: https://packagist.org/packages/aiken/i18next
- Size: 24.4 KB
- Stars: 13
- Watchers: 5
- Forks: 15
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
i18next-php
===================
PHP class for basic [i18next](https://github.com/jamuhl/i18next) functionality.## Features
- Support for [variables](http://i18next.com/pages/doc_features.html#interpolation)
- Support for [context](http://i18next.com/pages/doc_features.html#context)
- Support for [basic sprintf](http://i18next.com/pages/doc_features.html#sprintf)
- Support for [basic plural forms](http://i18next.com/pages/doc_features.html#plurals)
- Support for [multiline in JSON](http://i18next.com/pages/doc_features.html)## Usage
```php
// init i18next instance
i18next::init('en');// get translation by key
echo i18next::getTranslation('animal.dog');
```## Methods
### i18next::init( string $languageKey [, string $path ] );
Loads translation files from given path. Looks for `translation.json` by default.
```php
i18next::init('en', 'my/path/');
// loads my/path/translation.json
```
You can also use variables and split namespaces and languages to different files.
```php
i18next::init('en', 'languages/__lng__/__ns__.json');
// loads languages/en/animal.json, languages/fi/animal.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.
```php
i18next::getTranslation('animal.catWithCount', 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) "animal.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"
]
}
}
}
```