Internationalization

Phalcon is written in C as an extension for PHP. There is a PECL extension that offers internationalization functions to PHP applications called intl. Starting from PHP 5.4/5.5 this extension is bundled with PHP. Its documentation can be found in the pages of the official PHP manual.

Phalcon does not offer this functionality, since creating such a component would be replicating existing code.

In the examples below, we will show you how to implement the intl extension's functionality into Phalcon powered applications.

Find out best available Locale

There are several ways to find out the best available locale using intl. One of them is to check the HTTP Accept-Language header:

Locale-Sensitive comparison

The Collator class provides string comparison capability with support for appropriate locale-sensitive sort orderings. Check the examples below on the usage of this class:

<?php
// Create a collator using Spanish locale
$collator = new Collator('es');
// Returns that the strings are equal, in spite of the emphasis on the 'o'
$collator->setStrength(Collator::PRIMARY);
var_dump($collator->compare('una canción', 'una cancion'));
// Returns that the strings are not equal
$collator->setStrength(Collator::DEFAULT_VALUE);
var_dump($collator->compare('una canción', 'una cancion'));