PHPackages                             nabeghe/light-localization - 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. nabeghe/light-localization

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

nabeghe/light-localization
==========================

A light weight, key-value &amp; path-based PHP localization library that translations are loaded up when needed.

v2.0.2(2mo ago)3107↓75%MITPHPPHP &gt;=7.4

Since Jan 19Pushed 2mo ago1 watchersCompare

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

READMEChangelog (10)Dependencies (4)Versions (13)Used By (0)

Light Localization
==================

[](#light-localization)

 [![](https://private-user-images.githubusercontent.com/12207627/452813068-b14ef73b-a458-4d7f-84f8-8ce6b8d84740.jpg?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzUwMTU1MjgsIm5iZiI6MTc3NTAxNTIyOCwicGF0aCI6Ii8xMjIwNzYyNy80NTI4MTMwNjgtYjE0ZWY3M2ItYTQ1OC00ZDdmLTg0ZjgtOGNlNmI4ZDg0NzQwLmpwZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjA0MDElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwNDAxVDAzNDcwOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWVmNDcwNjQxYjNhMjg0YTU1NTE0MTM4NTM0NjIwNDhmNmE2NjkxYTdkMjMwMDkxYzM0MjM4YTZiM2JmNTYzNTcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.oWqCKzonhAxbWucTHHTnry0ScfoSqE9zvnViFBZ89uA)](https://private-user-images.githubusercontent.com/12207627/452813068-b14ef73b-a458-4d7f-84f8-8ce6b8d84740.jpg?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzUwMTU1MjgsIm5iZiI6MTc3NTAxNTIyOCwicGF0aCI6Ii8xMjIwNzYyNy80NTI4MTMwNjgtYjE0ZWY3M2ItYTQ1OC00ZDdmLTg0ZjgtOGNlNmI4ZDg0NzQwLmpwZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjA0MDElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwNDAxVDAzNDcwOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWVmNDcwNjQxYjNhMjg0YTU1NTE0MTM4NTM0NjIwNDhmNmE2NjkxYTdkMjMwMDkxYzM0MjM4YTZiM2JmNTYzNTcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.oWqCKzonhAxbWucTHHTnry0ScfoSqE9zvnViFBZ89uA)

> A lightweight, key-value &amp; path-based PHP localization library.
> Translation groups are loaded lazily — only when first accessed.

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

[](#requirements)

- PHP &gt;= 7.4
- [nabeghe/atlin](https://github.com/nabeghe/atlin-php)

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

[](#installation)

```
composer require nabeghe/light-localization
```

Directory Structure
-------------------

[](#directory-structure)

Organize your translations like this:

```
/langs/
  /en/
      main.php
      messages.php
      extra.atlin
  /fa/
      main.php
      extra.atlin

```

- Each sub-directory represents a **locale code**.
- Each file inside is a **translation group** (identified by filename without extension).
- Files can be `.php` (returning an array) or `.atlin` format.
- `.atlin` files take precedence over `.php` when both exist for the same group name.

Quick Start
-----------

[](#quick-start)

```
use Nabeghe\LightLocalization\Localizer;

$en = new Localizer(__DIR__ . '/langs', 'en');
$fa = new Localizer(__DIR__ . '/langs', 'fa', $en); // $en is the fallback

// Reads from main.php (default group)
echo $fa->get('title');

// Reads from messages.php
echo $fa->get('success', 'messages');

// Returns a random item when the value is an array
echo $fa->rnd('greet');
```

Constructor
-----------

[](#constructor)

```
new Localizer(
    string $path,
    string $locale = 'en',
    Localizer|string|null $fallback = null,
    ?string $defaultTranslationText = null,
    ?Atlin $atlin = null
);
```

ParameterDescription`$path`Absolute path to the translations root directory`$locale`Active locale code`$fallback`Another `Localizer` to chain, or a plain string used as default`$defaultTranslationText`Returned when no translation is found anywhere in the chain`$atlin`Custom `Atlin` instance; created automatically if `null`Translation Files
-----------------

[](#translation-files)

### PHP

[](#php)

Return a plain associative array. Values can be strings or arrays of strings (for `rnd()`).

```
