GT ClassMethodsLocales

isSameLanguage

API Reference for the GT isSameLanguage method

Overview

The isSameLanguage method checks if multiple BCP-47 locale codes represent the same base language, ignoring regional and script differences. This is useful for determining language compatibility and grouping content by language family.


Reference

Parameters

Prop

Type

Returns

boolean - true if all locale codes represent the same base language


Examples

const gt = new GT({
  sourceLocale: 'en-US',
  targetLocale: 'es-ES'
});


// Same language, different regions
console.log(gt.isSameLanguage('en-US', 'en-GB')); // true
console.log(gt.isSameLanguage('es-ES', 'es-MX')); // true
console.log(gt.isSameLanguage('zh-CN', 'zh-TW')); // true

// Different languages
console.log(gt.isSameLanguage('en-US', 'es-ES')); // false
console.log(gt.isSameLanguage('fr-FR', 'de-DE')); // false

// Base language with variants
console.log(gt.isSameLanguage('en', 'en-US', 'en-GB')); // true

Notes

  • Compares only the base language code (before first hyphen)
  • Ignores regional, script, and variant differences
  • Essential for language-based content organization
  • Works with variable number of locale parameters

Next Steps

How is this guide?

isSameLanguage