Utility FunctionsLocales
isSupersetLocale
API reference for the isSupersetLocale function
Overview
The isSupersetLocale function checks whether one locale is a superset of another in the BCP‑47 hierarchy without requiring a GT class instance.
Reference
Parameters
Prop
Type
Returns
boolean — true if superLocale is a superset of subLocale
Examples
import { isSupersetLocale } from 'generaltranslation';
// The base language is a superset of the regional variant
console.log(isSupersetLocale('en', 'en-US')); // true
console.log(isSupersetLocale('es', 'es-ES')); // true
// The regional variant is NOT a superset of the base language
console.log(isSupersetLocale('en-US', 'en')); // false
// The same locales are supersets of themselves
console.log(isSupersetLocale('en-US', 'en-US')); // trueNotes
- Uses the BCP‑47 locale hierarchy
- Base languages are supersets of regional variants
- A locale is always a superset of itself
- Essential for building fallback systems
Next steps
- Use the GT class method
isSupersetLocale - Compare languages with
isSameLanguage
How is this guide?