Utility FunctionsLocales

isSameLanguage

API reference for the isSameLanguage function

Overview

The isSameLanguage function checks whether multiple BCP‑47 locale codes represent the same base language, ignoring regional differences.


Reference

Parameters

Prop

Type

Returns

booleantrue if all locale codes represent the same base language


Examples

import { isSameLanguage } from 'generaltranslation';

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

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

Notes

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

Next steps

How is this guide?

isSameLanguage