PHPackages                             carry0987/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. [Caching](/categories/caching)
4. /
5. carry0987/i18n

ActiveLibrary[Caching](/categories/caching)

carry0987/i18n
==============

A modern internationalization system featuring JSON-format language files and efficient PHP-based caching. Supports dynamic language switching and real-time cache updates, ideal for rapid development and deployment of multilingual websites and applications.

2.1.6(8mo ago)22341MITPHPPHP &gt;=8.0CI passing

Since Nov 9Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/carry0987/PHP-I18n)[ Packagist](https://packagist.org/packages/carry0987/i18n)[ RSS](/packages/carry0987-i18n/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (10)Dependencies (2)Versions (24)Used By (1)

PHP-I18n
========

[](#php-i18n)

[![Packgist](https://camo.githubusercontent.com/05b2ebce5803ad9b2e23fb4e474999f04d775063cc2f97306556a1bc2955819e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6361727279303938372f6931386e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/carry0987/i18n)[![CI](https://github.com/carry0987/PHP-I18n/actions/workflows/CI.yml/badge.svg)](https://github.com/carry0987/PHP-I18n/actions/workflows/CI.yml/badge.svg)
A modern internationalization system featuring JSON-format language files and efficient PHP-based caching. Supports dynamic language switching and real-time cache updates, ideal for rapid development and deployment of multilingual websites and applications.

Features
--------

[](#features)

- Supports multiple language files
- Automatic caching of translation data for improved performance
- Supports organization of translation keys by namespaces
- Configurable translation file directory and cache directory

Requirements
------------

[](#requirements)

- Composer

File Structure
--------------

[](#file-structure)

Here's an example of the expected file structure:

```
.
├── cache
├── lang
│   ├── en_US
│   │   ├── general.json
│   │   └── greeting.json
│   └── zh_TW
│       ├── general.json
│       └── greeting.json
├── src
│   ├── /...
│   └── I18n.php
└── vendor

```

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

[](#installation)

Use Composer to install the I18n class library into your project:

```
composer require carry0987/i18n
```

Usage
-----

[](#usage)

After installation, you can include the `I18n` class in your project with Composer's autoloading:

```
require_once 'vendor/autoload.php';

use carry0987\I18n\I18n;

$i18n = new I18n([
    'useAutoDetect' => true, // By default, the language is automatically detected
    'langFilePath' => 'path/to/lang',
    'cachePath' => 'path/to/cache'
]);
```

Fetch translations:

```
// Use file name and key to get the translation value
echo $i18n->fetch('greeting.hello'); // Outputs: "Hello"
```

Fetch multiple translations:

```
// Get multiple translations in the current language
$translations = $i18n->fetchList(); // Empty parameter returns all translations
```

Note
----

[](#note)

When accessing translations, the keys used must follow the format: `filename.key`, which ensures that each translation value is extracted from the specified file.

Advanced Usage
--------------

[](#advanced-usage)

If set `useAutoDetect` to `true`, the language will be automatically detected from the browser's `Accept-Language` header. If the language is not supported, the default language will be used. Also, if you want to change cookie settings, you can set the `cookie` option:

```
$config = array(
    'useAutoDetect' => true,
    //...
    'cookie' => array(
        'name' => 'lang',
        'expire' => time()+864000,
        'path' => '/',
        'domain' => '',
        'secure' => true,
        'httponly' => true
    )
);
```

You can set the language code manually:

```
$i18n = new I18n([
    'useAutoDetect' => false, // Set useAutoDetect to false to disable automatic language detection
    //...
]);
// Initialize the language settings
$i18n->initialize('en_US'); // 'en_US' is the language code
```

Load specific language files:

```
$i18n = new I18n([
    'allowedFiles' => ['general', 'greeting'], // Set the list of language files to be loaded
    //...
]);
```

Set language aliases:

```
// Define aliases for languages
$i18n->setLangAlias(array('en_US' => 'English', 'zh_TW' => '繁體中文'));

// Fetch the list of languages with their aliases
$aliasedLangList = $i18n->fetchLangList();
// Outputs: array('en_US' => 'English', 'zh_TW' => '繁體中文')
```

###  Health Score

39

—

LowBetter than 85% of packages

Maintenance61

Regular maintenance activity

Popularity15

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

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 ~32 days

Recently: every ~130 days

Total

23

Last Release

250d ago

Major Versions

1.2.2 → 2.0.02023-11-11

PHP version history (3 changes)1.0.0PHP &gt;=7.2

2.1.0PHP &gt;=8.0

2.0.4PHP &gt;=7.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/12984973?v=4)[carry0987](/maintainers/carry0987)[@carry0987](https://github.com/carry0987)

---

Top Contributors

[![carry0987](https://avatars.githubusercontent.com/u/12984973?v=4)](https://github.com/carry0987 "carry0987 (47 commits)")

---

Tags

cachecookiei18njsonphp8i18nlanguagephp-i18n

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[gettext/languages

gettext languages with plural rules

7532.0M12](/packages/gettext-languages)[aplus/language

Aplus Framework Language Library

2371.7M15](/packages/aplus-language)[laravel-lang/common

Easily connect the necessary language packs to the application

1583.6M32](/packages/laravel-lang-common)[vluzrmos/language-detector

Detect the language for your application using browser preferences, subdomains or route prefixes.

109567.5k3](/packages/vluzrmos-language-detector)[tractorcow/silverstripe-fluent

Simple localisation for Silverstripe

90432.1k28](/packages/tractorcow-silverstripe-fluent)[badinansoft/nova-language-switch

A Laravel Nova package to switch language in your application

26568.5k1](/packages/badinansoft-nova-language-switch)

PHPackages © 2026

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