PHPackages                             ganti/i18next-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. ganti/i18next-php

ActiveLibrary[Localization &amp; i18n](/categories/localization)

ganti/i18next-php
=================

PHP class for basic i18next functionality.

11641PHP

Since Sep 22Pushed 6y agoCompare

[ Source](https://github.com/ganti/i18next-php)[ Packagist](https://packagist.org/packages/ganti/i18next-php)[ RSS](/packages/ganti-i18next-php/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (1)Used By (0)

i18next-php
===========

[](#i18next-php)

PHP class for basic [i18next](https://www.i18next.com) functionality.

Features
--------

[](#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)

### Missing Features

[](#missing-features)

- Missing [interval plurals](http://i18next.com/pages/doc_features.html#plurals)
- Formatting [date, datetime, time, strings](https://www.i18next.com/translation-function/formatting)

Usage
-----

[](#usage)

### basic usage

[](#basic-usage)

```
// init i18next instance
i18next::init('en');

// get translation by key
echo  i18next::getTranslation('animal.cat');
```

**Output**: cat

### substitution of variables

[](#substitution-of-variables)

```
"common": {
	"name_age" : "{{name}} is {{age}} years old"
}
```

```
echo  i18next::getTranslation('common.name_age', array('name' => "Elisa", "age" => 32));
```

**Output**:

```
	Elisa is 32 years old

```

### plural forms

[](#plural-forms)

There are diffrent ways on how to store plural forms in json

```
"animal":{
	"dog": "dog",
	"dog_plural": "dogs",

	"cat": "{{count}} cat",
	"cat_plural": "{{count}} cats",

	"elephant": "{{count}} elephant",
	"elephant_0": "no elephants",
	"elephant_2": "{{count}} elephants",

	"spiderWithCount" : "{{count}} spider",
	"spiderWithCount_plural" : "{{count}} spiders",
	"spiderWithCount_plural_0" : "no spiders"
}
```

```
// get translation by key with plural forms
echo  i18next::getTranslation('animal.cat', array('count' => 2));
echo  i18next::getTranslation('animal.cat', 2);
```

**Output**:

```
   2 cats
   2 cats

```

```
echo  i18next::getTranslation('animal.elephant', array('count' => 0));
echo  i18next::getTranslation('animal.elephant', array('count' => 1));
echo  i18next::getTranslation('animal.elephant', array('count' => 2));
echo  i18next::getTranslation('animal.elephant', array('count' => 100));
```

**Output**:

```
   no elephants
   1 elephant
   2 elephants
   100 elephants

```

### Context

[](#context)

By providing a context you can differ translations. Eg. useful to provide gender specific translations.

```
"people":{
   "friend" : "A friend",
   "friend_female" : "A girlfriend",
   "friend_female_plural" : "{{count}} girlfriends",
   "friend_male" : "A boyfriend",
   "friend_male_0" : "no boyfriend",
   "friend_male_plural" : "{{count}} boyfriends"
}
```

```
echo  i18next::getTranslation('people.friend');
echo  i18next::getTranslation('people.friend', array('context' => 'female'));
echo  i18next::getTranslation('people.friend', array('count' => 2, 'context' => 'female'));
echo  i18next::getTranslation('people.friend', array('count' => 0, 'context' => 'male'));
echo  i18next::getTranslation('people.friend', array('count' => 1, 'context' => 'male'));
echo  i18next::getTranslation('people.friend', array('count' => 33, 'context' => 'male'));
```

**Output**:

```
   A friend
   A girlfirend
   2 girlfriends
   no boyfriends
   A boyfriend
   33 boyfriends

```

Methods
-------

[](#methods)

### i18next::init( string $languageKey \[, string $path \] );

[](#i18nextinit-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 \] );

[](#mixed-i18nextgettranslation-string-key--array-variables--)

Returns translated string by key.

```
i18next::getTranslation('common.cat', array('count' => 2, 'lng' => 'fi'));
```

### boolean i18next::existTranslation( string $key );

[](#boolean-i18nextexisttranslation-string-key-)

Checks if translated string exists.

### void i18next::setLanguage( string $language \[, string $fallback \] );

[](#void-i18nextsetlanguage-string-language--string-fallback--)

Changes language.

### array i18next::getMissingTranslations();

[](#array-i18nextgetmissingtranslations)

Gets an array of missing translations.

```
array(1) {
	[0]=> array(2) {
	["language"]=> string(2) "en"
	["key"]=> string(14) "common.unknown"
	}
}
```

Multilines in JSON-arrays
-------------------------

[](#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"]
       }
  }
}
```

Development
===========

[](#development)

Run Tests
---------

[](#run-tests)

`composer test`

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/944a6adcd9f8a2c521d242472278a4bc81de512bc2e0abac3c17bba8f3d4725c?d=identicon)[ganti](/maintainers/ganti)

---

Top Contributors

[![ganti](https://avatars.githubusercontent.com/u/28899559?v=4)](https://github.com/ganti "ganti (29 commits)")[![Mika-](https://avatars.githubusercontent.com/u/5081253?v=4)](https://github.com/Mika- "Mika- (26 commits)")[![sinnwell](https://avatars.githubusercontent.com/u/1050182?v=4)](https://github.com/sinnwell "sinnwell (5 commits)")[![ideadapt](https://avatars.githubusercontent.com/u/1071386?v=4)](https://github.com/ideadapt "ideadapt (2 commits)")[![JosefMor](https://avatars.githubusercontent.com/u/3066976?v=4)](https://github.com/JosefMor "JosefMor (2 commits)")

### Embed Badge

![Health badge](/badges/ganti-i18next-php/health.svg)

```
[![Health](https://phpackages.com/badges/ganti-i18next-php/health.svg)](https://phpackages.com/packages/ganti-i18next-php)
```

###  Alternatives

[smmoosavi/php-gettext

Wrapper for php-gettext by danilo segan. This library provides PHP functions to read MO files even when gettext is not compiled in or when appropriate locale is not present on the system.

1926.6k1](/packages/smmoosavi-php-gettext)[laradevs/spanish

labels translated to spanish

166.7k](/packages/laradevs-spanish)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
