2017 © Pedro PelĂĄez
 

library l10n

Limoncello framework localization support.

image

limoncello-php/l10n

Limoncello framework localization support.

  • Wednesday, July 25, 2018
  • by neomerx
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1,428 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 49 Versions
  • 10 % Grown

The README.md

Scrutinizer Code Quality Code Coverage Build Status License, (*1)

Summary

This is localization component for Limoncello Framework., (*2)

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., (*3)

Message Localization

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

    $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., (*5)

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., (*6)

The result would contain the found message with their locale. For example, (*7)

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

If resources for requested locale de_AT existed the result could look like, (*8)

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

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., (*9)

For instance, there is a resource folder structure, (*10)

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

Where Messages.php is a plain PHP array file, (*11)

```php Resource/de/Messages.php <?php return [ 'Hello World' => 'Hallo Welt', ];, (*12)

and

```php Resource/de_AT/Messages.php
<?php
return [
    'Hello World' => 'Hallo Welt aus Österreich',
];

Then, a storage array could be created as, (*13)

    $storageData = (new FileBundleEncoder('path/to/ResourcesFolder/'))->getStorageData('de');

Method getStorageData has a default locale code as a first parameter., (*14)

Finally, complete example, (*15)

    $storageData = (new FileBundleEncoder('path/to/ResourcesFolder/'))->getStorageData('de');
    $localized = (new BundleStorage($storageData))->get('de_AT', 'ErrorMessages', 'Hello World');
    // $localized
    ['Hallo Welt aus Österreich', 'de_AT'];

Message Translation

In addition to Resource Storage, the package provides a helpful wrapper over MessageFormatter., (*16)

    $storageData = (new FileBundleEncoder('path/to/ResourcesFolder/'))->getStorageData('en');
    $translator = new Translator(new BundleStorage($storageData));

    // 'Hallo Welt' (message is in the resources)
    $translator->translateMessage('de', 'Messages', 'Hello World');

    // 'Hallo Welt aus Österreich' (message is in the resources)
    $translator->translateMessage('de_AT', 'Messages', 'Hello World');

    // 'Good morning' (message not found in resources so it returns the key itself)
    $translator->translateMessage('de', 'Messages', 'Good morning');

Method translateMessage has signature translateMessage(string $locale, string $namespace, string $key, array $args = []): string. The method can accept formatting parameters via $args parameter. For advanced formatting samples see MessageFormatter::formatMessage., (*17)

There is another wrapper for Translator called Formatter which hides locale code and namespace. It could be used in an environment where locale for current session is defined for a logged in user. So the code basically asks for FormatterInterface for current locale and specified namespace., (*18)

    $formatter = new Formatter('de', 'Messages', $translator);

    // 'Hallo Welt'
    $formatter->formatMessage('Hello World');

More info., (*19)

  • Have a resource folder with locales needed for your application.
  • For the resource folder and default locale create a storage data with FileBundleEncoder and cache it.
  • On page load read the storage data from the cache and load it into Translator with BundleStorage.
  • Use the translator for message formatting.

Testing

$ composer test

The Versions

25/07 2018

dev-develop

dev-develop https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

25/07 2018

dev-master

9999999-dev https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

25/07 2018

0.10.0

0.10.0.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

15/05 2018

0.9.1

0.9.1.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

15/05 2018

0.9.2

0.9.2.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

15/05 2018

0.9.3

0.9.3.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

19/03 2018

0.9.0

0.9.0.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

12/02 2018

0.8.10

0.8.10.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

19/01 2018

0.8.6

0.8.6.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

19/01 2018

0.8.7

0.8.7.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

19/01 2018

0.8.8

0.8.8.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

19/01 2018

0.8.9

0.8.9.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

07/12 2017

0.8.3

0.8.3.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

07/12 2017

0.8.4

0.8.4.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

07/12 2017

0.8.5

0.8.5.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

21/11 2017

0.8.1

0.8.1.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

21/11 2017

0.8.2

0.8.2.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

03/09 2017

0.8.0

0.8.0.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

16/08 2017

0.7.2

0.7.2.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

16/08 2017

0.7.3

0.7.3.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

16/08 2017

0.7.4

0.7.4.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

15/08 2017

0.7.1

0.7.1.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

14/08 2017

0.7.0

0.7.0.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

13/06 2017

0.6.14

0.6.14.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0.0
  • ext-intl *

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

13/06 2017

0.6.15

0.6.15.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0.0
  • ext-intl *

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

13/06 2017

0.6.16

0.6.16.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0.0
  • ext-intl *

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

13/06 2017

0.6.17

0.6.17.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0.0
  • ext-intl *

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

13/06 2017

0.6.18

0.6.18.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0.0
  • ext-intl *

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

01/06 2017

0.6.10

0.6.10.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0.0
  • ext-intl *

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

01/06 2017

0.6.11

0.6.11.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0.0
  • ext-intl *

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

01/06 2017

0.6.12

0.6.12.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0.0
  • ext-intl *

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

01/06 2017

0.6.13

0.6.13.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0.0
  • ext-intl *

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

01/06 2017

0.6.9

0.6.9.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0.0
  • ext-intl *

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

25/05 2017

0.6.8

0.6.8.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0.0
  • ext-intl *

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

09/05 2017

0.6.3

0.6.3.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0.0
  • ext-intl *

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

09/05 2017

0.6.4

0.6.4.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0.0
  • ext-intl *

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

09/05 2017

0.6.5

0.6.5.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0.0
  • ext-intl *

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

09/05 2017

0.6.6

0.6.6.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0.0
  • ext-intl *

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

09/05 2017

0.6.7

0.6.7.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support.

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0.0
  • ext-intl *

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

09/05 2017

0.6.2

0.6.2.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0.0
  • ext-intl *

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

07/04 2017

0.6.0

0.6.0.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0.0
  • ext-intl *

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

07/04 2017

0.6.1

0.6.1.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0.0
  • ext-intl *

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

20/03 2017

0.6.x-dev

0.6.9999999.9999999-dev https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0.0
  • ext-intl *

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

20/03 2017

0.5.3

0.5.3.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0.0
  • ext-intl *

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

20/03 2017

0.5.4

0.5.4.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0.0
  • ext-intl *

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

20/03 2017

0.5.5

0.5.5.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0.0
  • ext-intl *

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

18/03 2017

0.5.2

0.5.2.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0.0
  • ext-intl *

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

17/03 2017

0.5.0

0.5.0.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support

  Sources   Download

Apache-2.0

The Requires

  • php >=5.6.0
  • ext-intl *

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello

17/03 2017

0.5.1

0.5.1.0 https://github.com/limoncello-php/framework/tree/master/components/L10n

Limoncello framework localization support

  Sources   Download

Apache-2.0

The Requires

  • php >=5.6.0
  • ext-intl *

 

The Development Requires

by Avatar neomerx

framework localization l10n limoncello