W3cubDocs

/JavaScript

Intl.locale.maximize

The Intl.Locale.prototype.maximize() method gets the most likely values for the language, script, and region of the locale based on existing values.

Syntax

locale.maximize()

Return value

A Locale instance whose baseName property returns the result of the Add Likely Subtags algorithm executed against locale.baseName.

Description

Sometimes, it is convenient to be able to identify the most likely locale language identifier subtags based on an incomplete langauage ID. The Add Likely Subtags algorithm gives us this functionality. For instance, given the language ID "en", the algorithm would return "en-Latn-US", since English can only be written in the Latin script, and is most likely to be used in the United States, as it is the largest English-speaking country in the world. This functionality is provided to JavaScript programmers via the maximize() method. maximize() only affects the main subtags that comprise the language identifier: language, script, and region subtags. Other subtags after the "-u" in the locale indentifier are called extension subtags and are not affected by the maximize() method. Examples of these subtags include Locale.hourCycle, Locale.calendar, and Locale.numeric.

Examples

Using maximize

let myLocale = new Intl.Locale("fr", {hourCycle: "h24", calendar: "gregory"});
console.log(myLocale.baseName); // Prints "fr"
console.log(myLocale.toString()); // Prints "fr-u-ca-gregory-hc-h24"
let myLocMaximized = myLocale.maximize();

// Prints "fr-Latn-FR". The "Latn" and "FR" tags are added,
// since French is only written in the Latin script and is most likely to be spoken in France.
console.log(myLocMaximized.baseName); 

// Prints "fr-Latn-FR-u-ca-gregory-hc-h24". 
// Note that the extension tags (after "-u") remain unchanged.
console.log(myLocMaximized.toString()); 

Specifications

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
maximize 74 79 75 No 62 14
14
Safari 14 Technology Preview 107-111 returns a string instead of a Locale object.
Mobile
Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
maximize 74 74 No 53 14
14
Safari 14 Technology Preview 107-111 returns a string instead of a Locale object.
11.0
Server
Node.js
maximize 12.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() constructor for more details.

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/maximize