Pybabel or other l10n libraries for PHP

Babel or pybabel is an interface to CLDR (Common Locale Data Repository) in Python. Thus, it has the same β€œknowledge” as the PHP i18n functions and classes (if the corresponding locales are installed on the host), but without the hassle of using the parameters of the entire system, such as setlocale() .

Is there a similar library or toolkit for PHP? Especially to achieve:

  • Convert numbers to format and language for a specific language and region

  • also converts dates

  • access to names, monetary and other information in a specific locale (for example,

     >>> from babel import Locale >>> locale = Locale('en', 'US') >>> locale.territories['US'] u'United States' >>> locale = Locale('es', 'MX') >>> locale.territories['US'] u'Estados Unidos' 
+4
source share
1 answer

PHP 5.3 comes with an intl extension:

The internationalization extension (hereinafter referred to as Intl) is a wrapper for the ICU library, allowing PHP programmers to perform UCA-compatible sorting and date / time / number / currency formatting in their scripts.

  • Converting numbers is possible using the NumberFormatter class:

     $fmt = new NumberFormatter("de_DE", NumberFormatter::DECIMAL); echo $fmt->format(1234567.891234567890000); 
  • Date conversion is possible using the IntlDateFormatter class:

     $fmt = new IntlDateFormatter("en_US", IntlDateFormatter::FULL, IntlDateFormatter::FULL, 'America/Los_Angeles', IntlDateFormatter::GREGORIAN); echo $fmt->format(0); 
  • Access to names, monetary and other information in a specific locale is possible using the Locale class:

     echo Locale::getRegion('de-CH-1901'); 

In addition, there are Collation and MessageFormatter classes.

+2
source

Source: https://habr.com/ru/post/1303091/


All Articles