PHPackages                             webiik/translation - 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. webiik/translation

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

webiik/translation
==================

The Translation provides i18n translation.

1.1(6y ago)0662MITPHPPHP &gt;=7.2

Since Mar 28Pushed 6y ago1 watchersCompare

[ Source](https://github.com/webiik/translation)[ Packagist](https://packagist.org/packages/webiik/translation)[ Docs](https://www.webiik.com)[ RSS](/packages/webiik-translation/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (1)Versions (3)Used By (2)

[![](https://camo.githubusercontent.com/a397347ee4fb199934fee6354504f4702b89f5c22f0ce0ba94c5ff691cde545c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f77656269696b2f77656269696b2e737667)](https://camo.githubusercontent.com/a397347ee4fb199934fee6354504f4702b89f5c22f0ce0ba94c5ff691cde545c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f77656269696b2f77656269696b2e737667)[![](https://camo.githubusercontent.com/bdb417a12aecf0f18d2522ead57fa9c3d6f72238f05a20e8169bcd816f5ee809/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646570656e64656e636965732d312d627269676874677265656e2e737667)](https://camo.githubusercontent.com/bdb417a12aecf0f18d2522ead57fa9c3d6f72238f05a20e8169bcd816f5ee809/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646570656e64656e636965732d312d627269676874677265656e2e737667)

Translation
===========

[](#translation)

The translation provides i18n with user-extensible translation formatting.

Installation
------------

[](#installation)

```
composer require webiik/translation
```

Example
-------

[](#example)

```
$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']);
```

Setting
-------

[](#setting)

### setLang

[](#setlang)

```
setLang(string $lang): void
```

**setLang()** sets current lang of translation. This lang is used for setting and getting values to/from Translation class.

```
$translation->setLang('en');
```

### inject

[](#inject)

```
inject(string $parserClassName, TranslationInjector $injector): void
```

**inject()** injects dependencies to specific parser. It is useful when you make your custom parser and you need to inject some external dependencies.

```
$translation->inject('Route', new \Webiik\Translation\TranslationInjector(function () use (&$router) {
    return [$router];
}));
```

Adding
------

[](#adding)

### add

[](#add)

```
add(string $key, string $val): void
```

**add()** adds translation by key. Read more about [supported translation formats](#translation-formatting).

```
$translation->add('greeting', 'Hello {name}!');
```

### addArr

[](#addarr)

```
addArr(array $translation, &$context = false): void
```

**addArr()** adds translations from array.

Note about resolving the key conflicts:

**Arrays values** - New value that is an array is merged with old value that is an array. If array key is a string, value of the new key replaces value of the old key.

**Mixed values** - New value that is a different type than old value, replaces old value. e.g. New string value replaces old array value and vice-versa.

```
$translation->addArr(['greeting' => 'Hello {name}!']);
```

Getting
-------

[](#getting)

### get

[](#get)

```
get(string $key, array|bool|null $parse = null): string|array
```

**get()** gets translation by key. Key supports dot notation. If key is missing it returns empty string. After calling, all missing keys and contexts can be obtained with method **getMissing()**.

```
$translation->get('greeting', ['name' => 'Kitty']);
```

### getAll

[](#getall)

```
getAll(array|bool|null $parse = null): array
```

**getAll()** gets all translations. After calling, all missing contexts can be obtained with method **getMissing()**.

```
$translation->getAll(['name' => 'Kitty']);
```

### getMissing

[](#getmissing)

```
getMissing(): array
```

**getMissing()** returns array of all missing keys and contexts from callings of methods get() and getAll().

```
$missing = $translation->$arr->getMissing();
```

Parsing
-------

[](#parsing)

Translations can contain special formatting which help to update translation values on the fly.

#### Basic Syntax

[](#basic-syntax)

```
{var}

```

You can add any variable to translation with folded brackets.

```
$translation->add('greeting', 'Hello {name}!');
echo $translation->get('greeting', ['name' => 'Kitty']);
// Hello Kitty!
```

#### Plural Syntax

[](#plural-syntax)

```
{variableName, Plural, {int message}...}

```

Sometimes a translation depends on some specific count. **Int** allowed values are: **int, int-int, int-, int+**

```
$translation->add('cats', '{numCats, Plural, {0- No cats.} {1 One cat.} {2+ {numCats} cats.}}');
echo $translation->get('cats', ['numCats' => 2]);
// 2 cats.
```

#### Select Syntax

[](#select-syntax)

```
{variableName, Select, {condition message}...}

```

Sometimes a translation depends on some specific value. In the select syntax, **string** represents that value.

```
$translation->add('hello-cat', '{gender, Select, {male Hello Tom!} {female Hello Kitty!}}');
echo $translation->get('hello-cat', ['gender' => 'male']);
// Hello Tom!
```

#### Link Syntax

[](#link-syntax)

```
{Link, {link text} {url} {target} {rel}}

```

If you need to generate links and don't want to use HTML.

```
$translation->add('link', 'Visit the {Link, {official page} {https://www.webiik.com} {_blank} {nofollow}}.');
echo $translation->get('link', true);
// Visit the official website.
```

> ⚠️ Notice the true parameter when calling the method `get`. Without it, the link would be not generated, and the text of translation would be displayed in the original format.

#### Custom Parser Syntax

[](#custom-parser-syntax)

```
{variableName, FormatterClassName, formatter syntax}

```

or

```
{FormatterClassName, formatter syntax}

```

You can write your own parser. Every custom parser must:

- be compatible with the syntax above
- implement **Webiik\\Translation\\Parser\\ParserInterface.php**
- use namespace **Webiik\\Translation\\Parser**

Look at [Select](Parser/Select.php) parser to get better insight.

Resources
---------

[](#resources)

- [Webiik framework](https://github.com/webiik/webiik)
- [Report issue](https://github.com/webiik/components/issues)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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.

###  Release Activity

Cadence

Every ~300 days

Total

2

Last Release

2302d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1226362d003d186b45e7dfa44489c36af37196c6a1b476206700eaf4e9c96a5a?d=identicon)[Jiri Mihal](/maintainers/Jiri%20Mihal)

---

Top Contributors

[![Jiri-Mihal](https://avatars.githubusercontent.com/u/10408123?v=4)](https://github.com/Jiri-Mihal "Jiri-Mihal (277 commits)")

---

Tags

i18ntranslation

### Embed Badge

![Health badge](/badges/webiik-translation/health.svg)

```
[![Health](https://phpackages.com/badges/webiik-translation/health.svg)](https://phpackages.com/packages/webiik-translation)
```

###  Alternatives

[jenssegers/date

A date library to help you work with dates in different languages

1.8k11.2M80](/packages/jenssegers-date)[gettext/gettext

PHP gettext manager

70530.2M102](/packages/gettext-gettext)[fightbulc/moment

Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js

9693.2M10](/packages/fightbulc-moment)[jms/translation-bundle

Puts the Symfony Translation Component on steroids

42510.8M63](/packages/jms-translation-bundle)[lexik/translation-bundle

This bundle allows to import translation files content into the database and provide a GUI to edit translations.

4362.7M19](/packages/lexik-translation-bundle)[sonata-project/translation-bundle

SonataTranslationBundle

771.7M10](/packages/sonata-project-translation-bundle)

PHPackages © 2026

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