Skip to content

Locale metadata

Translate language, country, script, calendar, and currency codes into their localised display names — and a couple of handy extras (text direction, flag emoji). Every method falls back to the instance locale's own subtags when called without an argument.

Language, country, script, calendar

const fa = new Cosmo("fa");
fa.language("en");            // "انگلیسی"
fa.country("AU");            // "استرالیا"

const en = new Cosmo("en");
en.script("Latn");           // "Latin"
en.calendar("buddhist");     // "Buddhist Calendar"
Cosmo fa = new Cosmo("fa");
fa.language("en");           // "انگلیسی"
fa.country("AU");            // "استرالیا"

Cosmo en = new Cosmo("en");
en.script("Latn");           // "Latin"
en.calendar("buddhist");     // "Buddhist Calendar"
$fa = new Cosmo('fa');
$fa->language('en');          // "انگلیسی"
$fa->country('AU');           // "استرالیا"

$en = new Cosmo('en');
$en->script('Latn');          // "Latin"
$en->calendar('buddhist');    // "Buddhist Calendar"
fa = Cosmo("fa")
fa.language("en")            # "انگلیسی"
fa.country("AU")             # "استرالیا"

en = Cosmo("en")
en.script("Latn")            # "Latin"
en.calendar("buddhist")      # "Buddhist Calendar"

Called with no argument, each uses the instance locale: new Cosmo('en_AU')'s country() returns "Australia", language() returns "English".

Direction & flag

new Cosmo("fa").direction();    // "rtl"
new Cosmo("en").direction();    // "ltr"
new Cosmo("en-AU").flag();      // "🇦🇺"
new Cosmo("fa").direction();    // "rtl"
new Cosmo("en").direction();    // "ltr"
new Cosmo("en_AU").flag();      // "🇦🇺"
new Cosmo('fa')->direction();   // "rtl"
new Cosmo('en')->direction();   // "ltr"
new Cosmo('en_AU')->flag();     // "🇦🇺"
Cosmo("fa").direction()         # "rtl"
Cosmo("en").direction()         # "ltr"
Cosmo("en_AU").flag()           # "🇦🇺"

flag() is pure Unicode codepoint math (region letters → regional-indicator symbols), so no data table is involved. direction() resolves likely subtags first, so even script-only or minority RTL languages are detected correctly.

Currency name & symbol

const c = new Cosmo("en-US");
c.currency("AUD");              // "Australian Dollar"
c.currency("AUD", true);        // "A$"
Cosmo c = new Cosmo("en_US");
c.currency("AUD");                  // "Australian Dollar"
c.currency("AUD", true, false);     // "A$"   (symbol, strict)
$c = new Cosmo('en_US');
$c->currency('AUD');            // "Australian Dollar"  (localised name)
$c->currency('AUD', true);      // "A$"                 (disambiguated symbol)
c = Cosmo("en_US")
c.currency("AUD")               # "Australian Dollar"
c.currency("AUD", True)         # "A$"

The symbol form returns the standard, disambiguated symbol ("A$" for AUD in en_US), not the ambiguous narrow "$".

Likely subtags

Maximising/minimising a locale (enen-Latn-US) is available in JavaScript, Python, and Java (addLikelySubtags() / removeLikelySubtags()add_likely_subtags() / remove_likely_subtags() in Python). PHP's intl extension does not expose the likely-subtags algorithm, so it is the one port without these. See Platform notes.