MessageFormatOptions.localeCodeFromKey property

If defined, used by compileModule() to identify and map keys to the locale identifiers used by formatters and plural rules. The values returned by the function should match the locale argument.

Default: undefined

Signature:

localeCodeFromKey?: ((key: string) => string | null | undefined) | null;

Example

// Support all recognised Unicode locale identifiers
function localeCodeFromKey(key) {
  try {
    // Ignore all language subtags
    return new Intl.Locale(key).language
  } catch {
    return null
  }
}