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

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

whoa-php/l10n
=============

Whoa framework localization support.

044PHP

Since Jul 22Pushed 3y agoCompare

[ Source](https://github.com/whoa-php/l10n)[ Packagist](https://packagist.org/packages/whoa-php/l10n)[ RSS](/packages/whoa-php-l10n/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/f27b76060c4eb776cd10ec9f50b7a7de9f6c425c43e5c7500c6e418c74edbf48/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f77686f612d7068702f6c31306e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/whoa-php/l10n/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/0c15dc9b809a6ef440f3b560297a8fca2584044ce3450ed6a6adc712331788ce/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f77686f612d7068702f6c31306e2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/whoa-php/l10n/?branch=master)[![Build Status](https://camo.githubusercontent.com/a49cd83499e7a0a278aee6410adac5a982c9687b741fbb856a094a3d74e7eb31/68747470733a2f2f7472617669732d63692e6f72672f77686f612d7068702f6c31306e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/whoa-php/l10n)[![License](https://camo.githubusercontent.com/29e42c41dfd32af574ac33640bd77cf680f497a44708a301b4d936747323560e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f77686f612d7068702f6c31306e2e737667)](https://packagist.org/packages/whoa-php/l10n)

Summary
-------

[](#summary)

This is localization component for [Whoa Framework](https://github.com/whoa-php/l10n).

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

```
