Intl.Locale maximize Resolves Likely Subtags
Use Intl.Locale maximize and minimize to resolve likely subtags, then attach calendar and numbering options to the tag.
Code
const locale = new Intl.Locale('zh-hk');
console.log('tag:', locale.toString());
console.log('maximized:', locale.maximize().toString());
console.log('minimized:', locale.minimize().toString());
console.log('language:', locale.language, '| region:', locale.region);
console.log('likely script:', locale.maximize().script);
const configured = new Intl.Locale('en', { calendar: 'gregory', numberingSystem: 'latn' });
console.log('with options:', configured.toString());
console.log('calendar:', configured.calendar, '| numbering:', configured.numberingSystem);
// maximize resolves likely subtags such as the script for zh-HK
const tags = ['zh-hant-hk', 'zh-hans-cn', 'zh-hk'];
const sorted = tags.sort((a, b) => new Intl.Collator('zh').compare(a, b));
console.log('tags sorted:', sorted.join(','));
const base = new Intl.Locale('sr-Latn-RS');
console.log('base name:', base.baseName, '| script:', base.script);
// maximize 不改变显式写出的子标签,只补缺省部分
const explicit = new Intl.Locale('en-Latn-US');
console.log('explicit maximized:', explicit.maximize().toString());Output
Captured from a sandboxed run of this snippet in the build pipeline.
tag: zh-HK
maximized: zh-Hant-HK
minimized: zh-HK
language: zh | region: HK
likely script: Hant
with options: en-u-ca-gregory-nu-latn
calendar: gregory | numbering: latn
tags sorted: zh-hans-cn,zh-hant-hk,zh-hk
base name: sr-Latn-RS | script: Latn
explicit maximized: en-Latn-USHow the snippet works
Top-level bindings locale, configured, tags, sorted hold the demo state — nothing sits inside a function scope.
Applying it
The run emits 10 labeled sections — tag:, maximized:, minimized:, language:, likely script:, with options:, calendar:, tags sorted:, base name:, explicit maximized: — one per step.
Statements that matter
const sorted = tags.sort((a, b) => new Intl.Collator('zh').compare(a, b));
const configured = new Intl.Locale('en', { calendar: 'gregory', numberingSystem: 'latn' });
const explicit = new Intl.Locale('en-Latn-US');
Interactive Tools for This Topic
Dotenv File ParserParse .env file content into a JSON object, handling comments, export prefixes, single quotes, and double-quoted escape sequences.INI File ParserParse INI configuration files into nested JSON with section objects, global keys, and both semicolon and hash comment support.JSON to TOML ConverterTurn a JSON object into TOML, emitting nested objects as tables and arrays of objects as array-of-tables blocks.JSON to YAML ConverterConvert JSON to readable YAML with nested block mappings, sequences, and quoting only where it is required.
FAQ
- Will the snippet run without installing packages?
- Yes, it runs as-is — nothing outside the built-in APIs is referenced. Its state lives in module-level bindings: `locale`, `configured`, `tags`.
Report a problem with this exampleOpens a pre-filled issue on GitHub.