Utility FunctionsLocales

requiresTranslation

API Reference for the requiresTranslation function

Overview

The requiresTranslation function determines whether translation is needed between source and target locales without requiring a GT class instance.


Reference

Parameters

Prop

Type

Returns

boolean - true if translation is required, false otherwise


Examples

import { requiresTranslation } from 'generaltranslation';

// Different languages require translation
console.log(requiresTranslation('en-US', 'es-ES')); // true
console.log(requiresTranslation('en-US', 'fr-FR')); // true

// Same languages don't require translation
console.log(requiresTranslation('en-US', 'en-US')); // false
console.log(requiresTranslation('en-US', 'en-GB')); // false

// With approved locales filter
const approved = ['en-US', 'es-ES', 'fr-FR'];
console.log(requiresTranslation('en-US', 'it-IT', approved)); // false (not approved)
console.log(requiresTranslation('en-US', 'es-ES', approved)); // true (approved and different)

Notes

  • Respects approved locale constraints
  • Returns false when target not in approved list
  • Considers custom locale mappings

Next Steps

How is this guide?

requiresTranslation