PHPackages                             openclerk/i18n - 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. openclerk/i18n

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

openclerk/i18n
==============

A library for simple i18n management in PHP

0.1.0(8y ago)01461PHP

Since Sep 11Pushed 8y ago1 watchersCompare

[ Source](https://github.com/openclerk/i18n)[ Packagist](https://packagist.org/packages/openclerk/i18n)[ RSS](/packages/openclerk-i18n/feed)WikiDiscussions master Synced 1mo ago

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

openclerk/i18n [![Build Status](https://camo.githubusercontent.com/191d0ba42bbdcdafa22b7cf7c3d66de01238a52f8d0ed1856bc0e6408e23a168/68747470733a2f2f7472617669732d63692e6f72672f6f70656e636c65726b2f6931386e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/openclerk/i18n)
========================================================================================================================================================================================================================================================================================

[](#openclerki18n-)

A library for simple i18n management in PHP.

Installing
----------

[](#installing)

Include `openclerk/i18n` as a requirement in your project `composer.json`, and run `composer update` to install it into your project:

```
{
  "require": {
    "openclerk/i18n": "dev-master"
  }
}
```

Features
--------

[](#features)

TODO

Using
-----

[](#using)

```
I18n::addAvailableLocale(new FrenchLocale());   // implement your own Locale here

I18n::setLocale('fr');
echo t("hello");                  // returns 'bonjour'
echo I18n::getCurrentLocale();    // returns 'fr'
```

You can also listen to the `i18n_missing_string` event (with *openclerk/events*) to capture missing locale strings at runtime:

```
\Openclerk\Events::on('i18n_missing_string', function($data) {
  echo $data['locale'] . ": " . $data['key'];
});

echo t("missing string");   // prints "fr: missing string"
```

Providing i18n strings
----------------------

[](#providing-i18n-strings)

One easy way to implement a Locale is simply to define it in a JSON file:

```
class FrenchLocale implements \Openclerk\Locale {

  function getKey() {
    return 'fr';
  }

  function getTitle() {
    return 'French' /* i18n */;
  }

  function load() {
    $json = json_decode(__DIR__ . "/fr.json", true /* assoc */);
    return $json;
  }

}
```

For speed, you could also define this as a PHP file `require()` instead.

Providing i18n strings across multiple components and projects
--------------------------------------------------------------

[](#providing-i18n-strings-across-multiple-components-and-projects)

By using [component-discovery](https://github.com/soundasleep/component-discovery) along with [translation-discovery](https://github.com/soundasleep/translation-discovery), you can combine translation files across multiple projects and Composer dependencies at build time. For example:

```
abstract class DiscoveredLocale implements \Openclerk\Locale {

  function __construct($code, $file) {
    $this->code = $code;
    $this->file = $file;
  }

  function getKey() {
    return $this->code;
  }

  function load() {
    if (!file_exists($this->file)) {
      throw new \Openclerk\LocaleException("Could not find locale file for '" . $this->file . "'");
    }
    $result = array();
    require($this->file);
    return $result;
  }

}

class FrenchLocale extends DiscoveredLocale {

  public function __construct() {
    parent::__construct('fr', __DIR__ . "/../site/generated/translations/fr.php");
  }

}

\Openclerk\I18n::addAvailableLocales(DiscoveredComponents\Locales::getAllInstances());
```

(TODO: Add link to example project)

Persisting locale across sessions
---------------------------------

[](#persisting-locale-across-sessions)

When changing user locale, add a cookie:

```
setcookie('locale', $locale, time() + (60 * 60 * 24 * 365 * 10) /* 10 years in the future */);
```

And then check for this cookie as necessary:

```
if (isset($_COOKIE["locale"]) && in_array($_COOKIE["locale"], array_keys(I18n::getAvailableLocales()))) {
  I18n::setLocale($_COOKIE["locale"]);
}
```

Discovering translation strings
-------------------------------

[](#discovering-translation-strings)

The [soundasleep/translation-discovery](https://github.com/soundasleep/translation-discovery) project has a `find` script that can be used to search your project for translation strings that may need to be translated across all of your components.

This script will find all instances of the following translation strings, and output them to the `template` JSON folder:

1. `t("string")`
2. `ht("string")`
3. `plural("string", 1)` and `plural("string", "strings", 1)`
4. `"string" /* i18n */`
5. And the single-quote versions of these patterns

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity53

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

Unknown

Total

1

Last Release

3162d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1ebbec5ccc867054461adebb7c5b6312f8256f989ef96b124892e6e89724afdb?d=identicon)[soundasleep](/maintainers/soundasleep)

---

Top Contributors

[![soundasleep](https://avatars.githubusercontent.com/u/3889656?v=4)](https://github.com/soundasleep "soundasleep (15 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/openclerk-i18n/health.svg)

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

###  Alternatives

[symfony/translation

Provides tools to internationalize your application

6.6k836.5M2.0k](/packages/symfony-translation)[nesbot/carbon

An API extension for DateTime that supports 281 different languages.

169661.4M4.8k](/packages/nesbot-carbon)[joedixon/laravel-translation

A tool for managing all of your Laravel translations

717911.4k11](/packages/joedixon-laravel-translation)[illuminate/translation

The Illuminate Translation package.

6936.4M491](/packages/illuminate-translation)[lajax/yii2-translate-manager

Translation management extension for Yii 2

227578.8k13](/packages/lajax-yii2-translate-manager)[larswiegers/laravel-translations-checker

Make sure your laravel translations are checked and are included in all languages.

256423.2k2](/packages/larswiegers-laravel-translations-checker)

PHPackages © 2026

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