Internationalization

7 entries

Collator::sort Function ICU-powered locale sorting: a Collator carrying its own locale rules sorts an array in place (the locale-aware equivalent of sort()), and is the official replacement for strcoll/SORT_LOCALE_STRING deprecated as of PHP 8.6. Under en_US, apple sorts before Ápple — collation keys are maintained release-by-release by ICU and stable across platforms. gettext Function GNU gettext message translation: looks the msgid up in the current domain's .mo catalog, returning the translation when found and the msgid unchanged when not — this entry deliberately ships no catalog and demos the zero-dependency, genuinely runnable flow via the fallback behaviour (bindtextdomain + textdomain + the _() alias). idn_to_ascii Function Converts an internationalized domain name to IDNA ASCII (punycode): non-ASCII labels become xn-- labels, pure-ASCII ones are only lowercased; UTS #46 is the default variant. The Chinese domain 例子.cn becomes xn--fsqu00a.cn — the UTS #46 rules are frozen, so output is identical across ICU versions. IntlDateFormatter Function ICU's date-formatting binding for PHP: locale plus a canned style (SHORT/LONG/FULL) or an explicit pattern decides the output shape, and it can parse back to a timestamp. Sibling of JS Intl.DateTimeFormat and Java DateTimeFormatter.ofLocalizedDate. The example pins a UTC timestamp and uses explicit patterns to sidestep ICU version drift. NumberFormatter Function ICU's binding for number/currency/percent formatting: renders locale-specific number strings by locale and style (DECIMAL/CURRENCY/PERCENT/SPELLL and friends), with a reversible parse(). The example pins en_US asserting "1,234.56" — pure numeric patterns are stable across ICU versions; currency symbols drift far more, so they are discussed in the notes only, never in code. setlocale Function Sets the process-wide locale (the global school): categories such as LC_ALL/LC_NUMERIC/LC_TIME/LC_COLLATE govern subsequent libc behaviour; returns the locale that actually took effect, or false on failure. After a successful de_DE switch printf's decimal point becomes a comma — always restore afterwards. Transliterator Function The ICU transliteration engine: one ID chain generates slugs ("Any-Latin; Latin-ASCII; Lower(); [^a-z0-9] Remove") — "Crème Brûlée" folds to ASCII deterministically; Han-to-pinyin (Any-Latin) varies with the ICU version.