Utility FunctionsLocales
requiresTranslation
API reference for the requiresTranslation function
Overview
The requiresTranslation function determines whether a translation is needed between source and target locales without requiring a GT class instance.
Reference
Parameters
Prop
Type
Returns
boolean — true if a 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
// The same languages don’t require translation
console.log(requiresTranslation('en-US', 'en-US')); // false
console.log(requiresTranslation('en-US', 'en-GB')); // false
// With an 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 the target is not in the approved list
- Accounts for custom locale mappings
Next steps
- Use the GT class method
requiresTranslation - Compare languages with
isSameLanguage
How is this guide?