GT ClassMethodsLocales

resolveAliasLocale

API reference for the GT resolveAliasLocale method

Overview

The resolveAliasLocale method maps a canonical locale code back to its original alias locale code when custom mapping is configured. This is the inverse of resolveCanonicalLocale.


Reference

Parameters

Prop

Type

Parameter descriptions

ParameterDescription
localeThe canonical locale code to resolve to its alias
customMappingOptional custom mapping to use instead of the instance mapping

Returns

string - The alias locale code if a mapping exists; otherwise, the original locale code

Throws

  • Error — if no locale is provided and no target locale is configured

Examples

const gt = new GT({
  sourceLocale: 'en',
  customMapping: {
    'cn': { code: 'zh', name: 'Mandarin' },
  }
});

// Resolve canonical locale back to alias
const alias = gt.resolveAliasLocale('zh');
console.log(alias); // "cn"

// Non-mapped locale returns the original
const unchanged = gt.resolveAliasLocale('es');
console.log(unchanged); // "es"

Notes

  • Returns the original alias locale code when a custom mapping exists
  • Returns the input locale unchanged if no mapping is found

Next steps

How is this guide?

resolveAliasLocale