PHPackages                             lolltec/limoncello-php-component-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. [Localization &amp; i18n](/categories/localization)
4. /
5. lolltec/limoncello-php-component-l10n

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

lolltec/limoncello-php-component-l10n
=====================================

Limoncello framework localization support.

0106PHP

Since Jun 12Pushed 5y agoCompare

[ Source](https://github.com/lolltec/limoncello-php-component-l10n)[ Packagist](https://packagist.org/packages/lolltec/limoncello-php-component-l10n)[ RSS](/packages/lolltec-limoncello-php-component-l10n/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (2)Used By (0)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/42daf29864f0eaf0db2e8b3781ae78c2346d5a6f6df672a2067da45c44661abe/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c6f6c6c7465632f6c696d6f6e63656c6c6f2d7068702d636f6d706f6e656e742d6c31306e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/lolltec/limoncello-php-component-l10n/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/66bb9dec1d5610be971f58ec1fe4736f9a2b1c5f07ae74ecdfefb7e95ca88cad/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c6f6c6c7465632f6c696d6f6e63656c6c6f2d7068702d636f6d706f6e656e742d6c31306e2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/lolltec/limoncello-php-component-l10n/?branch=master)[![Build Status](https://camo.githubusercontent.com/a0cff859eb69a9c28d9778dddd610933a797beca6615ce78ca23e05e6e84aae5/68747470733a2f2f7472617669732d63692e6f72672f6c6f6c6c7465632f6c696d6f6e63656c6c6f2d7068702d636f6d706f6e656e742d6c31306e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/lolltec/limoncello-php-component-l10n)[![License](https://camo.githubusercontent.com/b54ddd4ab37d21b97a4a8f13f45d8aa343eea8e04ae333efa0323d62d258b10e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6c6f6c6c7465632f6c696d6f6e63656c6c6f2d7068702d6672616d65776f726b2e737667)](https://packagist.org/packages/lolltec/limoncello-php-framework)

Summary
-------

[](#summary)

This is localization component for [Limoncello Framework](https://github.com/lolltec/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

```
