scento/lingua

This package is abandoned and no longer maintained. No replacement package was suggested.

Lingua is an internationalization toolkit.

1.0.0 2016-09-19 13:18 UTC

This package is not auto-updated.

Last update: 2020-01-24 15:32:02 UTC


README

Build Status Coverage Status Packagist Version Dependencies

Motivation

Imagine you have to develop a web application for a worldwide audience. How do you manage to respect the cultural differences of the people you are working for on different levels? The problematic fields not only cover the language and different input methods, but also charsets, timezones, regional dialects, units and many other things, which are standardized per-country or per-region.

This project aims to support the development of interculural PHP applications by providing standardized interfaces and classes to utilize global coding standards and a buch of conversion table resources to provide a unified library for Locale management.

The library is supposed to integrate into existing PHP frameworks and works with a minimal configuration effort, while being highly modular, keeping the ability to change every subsystem, depending on the project needs.

Installation

One can download and install this library using composer:

composer require scento/lingua

Lingua needs to download some data before being able to work. The entire process can happen automatically, but you need to accept the different licenses of the sources to use the data. Whenever you need to embed this library into own projects, remember to integrate a way to trigger this process including showing the licenses.

<?php
//Create a preinitialized setup environment
$setup = Lingua\Setup::prelude();

//Showing all terms of use
echo "You accept the the following terms of use:";
foreach ($setup->getLicenses() as $source => $license) {
    echo "\n\n---\t".$source."\t---\n";
    echo $license."\n";
}

//Download and process the required data
$setup->acceptAndDownload();

The Setup process can utilize a PSR-3 logging handler.

Use Cases

Lingua support many different use cases, some of them are described or shown in the examples. Some advanced use cases are described in the in-detail documentation. The current version supports:

Code Conversion

The following lines show the basic method to translate between coding standards. There are more examples available.

<?php
$iso639Part1 = new Lingua\Code\Language\ISO639Part1();
$iso639Part2B = new Lingua\Code\Language\ISO639Part2B();

echo $iso639Part2B->translate($iso639Part1->unify('de'));

Code Validation

The following example shows how to validate a code. Some more examples are available.

<?php
$iso15924 = new Lingua\Code\Script\ISO15924();
echo '`Latn` is '.($iso15924->validate('Latn') ? 'a' : 'no').' valid ISO 15924 code.';

Supported Standards

To unify and translate different resources depending on codings, this library supports the following standards:

Language Region Script
ISO 639-1 ISO 3166-1 Alpha-2 ISO 15924
ISO 639-2B ISO 3166-1 Alpha-3
ISO 639-2T
ISO 639-3

Development

To learn more about the development process, read our contribution guide - basically we follow and utilize:

Licenses

This project is licensed under the terms of the MIT License.