This part covers locales.
The documentation is divided into the following parts, mimicking Unicode's documentation:
- Part 1: Core (languages, locales, basic structure)
- Part 2: General (display names & transforms, etc.)
- Part 3: Numbers (number & currency formatting)
- Part 4: Dates (date, time, time zone formatting)
- Part 5: Collation (sorting, searching, grouping)
- Part 6: Supplemental (supplemental data)
The data and conventions of a locale are represented by a Locale instance, which can be used as an array to access various raw data such as calendars, characters, currencies, delimiters, languages, territories, and more.
<?php
/* @var ICanBoogie\CLDR\Repository $repository */
$locale = $repository->locale_for('fr');
echo $locale['characters']['auxiliary']; // [á å ä ã ā ē í ì ī ñ ó ò ö ø ú ǔ]
echo $locale['delimiters']['quotationStart']; // «
echo $locale['territories']['TF']; // Terres australes françaises
Locales provide a collection of calendars, and the calendar
property is often used to obtain the
default calendar of a locale.
<?php
use ICanBoogie\CLDR\Dates\CalendarId;
/* @var ICanBoogie\CLDR\Repository $repository */
$locale = $repository->locale_for('fr');
echo $locale['ca-gregorian']['days']['format']['wide']['sun']; // dimanche
# or using the calendar collection
echo $locale->calendar_for(CalendarId::GREGORIAN)['days']['format']['wide']['sun'];
# or because the Gregorian calendar is the default for this locale
echo $locale->calendar['days']['format']['wide']['sun'];
Locales are also often used to localize instances such as Currency, Territory, or even
Locale. The method localize
is used to localize instances. The method tries its best to find a
suitable localizer, and it helps if the instance to localize implements Localizable, or if a
ICanBoogie\CLDR\Localized<class_base_name>
class is defined.
<?php
/* @var \ICanBoogie\CLDR\Core\Locale $locale */
$datetime = new \DateTime;
$localized_datetime = new \ICanBoogie\CLDR\Dates\LocalizedDateTime($datetime, $locale);
Instances that can be localized usually implement the localize()
method.
<?php
/* @var ICanBoogie\CLDR\Repository $repository */
echo $repository->territory_for('FR')->localized('fr')->name; // France
A localized locale can be obtained with the localize()
method, or the localize()
method of the
desired locale.
<?php
/* @var ICanBoogie\CLDR\Repository $repository */
$locale = $repository->locale_for('fr');
echo $locale->localized($id)->name; // Français
# or
echo $repository->locale_for($id)->localized($locale)->name; // Français
Several capitalization contexts can be distinguished for which different languages use different
capitalization behavior for dates, date elements, names of languages/regions/currencies. The
context_transform()
method helps to capitalize these elements:
<?php
use ICanBoogie\CLDR\General\Transforms\ContextTransforms;
/* @var ICanBoogie\CLDR\Repository $repository */
echo $repository->locale_fr('fr')->context_transform(
"juin",
ContextTransforms::USAGE_MONTH_FORMAT_EXCEPT_NARROW,
ContextTransforms::TYPE_STAND_ALONE
);
// Juin