Utility FunctionsLocales

isSameLanguage

API Reference for the isSameLanguage function

Overview

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


Reference

Parameters

Prop

Type

Returns

boolean - true 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 first hyphen)
  • Ignores regional, script, and variant differences
  • Essential for language-based content organization
  • Works with variable number of parameters

Next Steps

How is this guide?

isSameLanguage