PHPackages                             limoncello-php/l10n - 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. [Framework](/categories/framework)
4. /
5. limoncello-php/l10n

ActiveLibrary[Framework](/categories/framework)

limoncello-php/l10n
===================

Limoncello framework localization support.

0.10.0(7y ago)02.4k3Apache-2.0PHPPHP &gt;=7.1.0

Since Mar 17Pushed 7y ago1 watchersCompare

[ Source](https://github.com/limoncello-php-dist/l10n)[ Packagist](https://packagist.org/packages/limoncello-php/l10n)[ Docs](https://github.com/limoncello-php/framework/tree/master/components/L10n)[ RSS](/packages/limoncello-php-l10n/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (6)Versions (49)Used By (3)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/37897075a25e8be65b6512adbee91320759ec1c9d3d0c425a6a97718d888e804/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c696d6f6e63656c6c6f2d7068702d646973742f6c31306e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/limoncello-php-dist/l10n/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/36388981380bdf355c077825da90dbd57ea88cb980ec5b676b43ec1dc1b5bf98/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c696d6f6e63656c6c6f2d7068702d646973742f6c31306e2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/limoncello-php-dist/l10n/?branch=master)[![Build Status](https://camo.githubusercontent.com/3720e162d63a1b59a4fa1b8bae1bb176f612b704a1631278c1c1a69c27bb1299/68747470733a2f2f7472617669732d63692e6f72672f6c696d6f6e63656c6c6f2d7068702d646973742f6c31306e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/limoncello-php-dist/l10n)[![License](https://camo.githubusercontent.com/3ee782c9b5e87cbec66eb902c2bc6b29d10e8190c9143176c95e07565e02f487/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6c696d6f6e63656c6c6f2d7068702f6672616d65776f726b2e737667)](https://packagist.org/packages/limoncello-php/framework)

Summary
-------

[](#summary)

This is localization component for [Limoncello Framework](https://github.com/limoncello-php/framework).

The component helps to translate an application into different languages. In particular, it provides an ability to manage localized files easily and extract localized strings for a given locale with a fallback to default one.

### Message Localization

[](#message-localization)

For a given resource storage data (later on this) the usage looks like

```
    $storage   = new BundleStorage($storageData);
    $localized = $storage->get('de_AT', 'ErrorMessages', 'id_or_message');
```

Where

- first parameter `de_AT` is a locale code.
- second parameter `ErrorMessages` is messages' namespace name. Using a namespace allows message isolation across namespaces. Typically namespace is a resource file name without `.php` file extension.
- third parameter `id_or_message` is a message identity. A message identity should be unique across a namespace.

It first finds the closest locale (`de_AT`, `de` or a default one such as `en` if no locale is found) and a corresponding message.

The result would contain the found message with their locale. For example

```
    // $localized
    ['Hallo Welt', 'de'];
```

If resources for requested locale `de_AT` existed the result could look like

```
    // $localized
    ['Hallo Welt aus Österreich', 'de_AT'];
```

### Resource Storage

[](#resource-storage)

In the example above resource storage data is an array that contains localized strings. The reason this object is introduced is a performance optimization. Looking for multiple files in a file system and analyzing their data is time and resource consuming. The storage data replaces many resource files with a single optimized for search array which could be cached.

For instance, there is a resource folder structure

```
Resources
    |_ de
        |_ Messages.php
    |_de_AT
        |_ Messages.php
```

Where `Messages.php` is a plain PHP array file

```
