Utility FunctionsLocales

requiresTranslation

requiresTranslation 函数的 API 参考

概览

requiresTranslation 函数无需 GT class 实例即可判断源 locale 与目标 locale 之间是否需要翻译。


参考资料

参数

Prop

Type

返回值

boolean - 需要翻译时为 true,否则为 false


示例

import { requiresTranslation } from 'generaltranslation';

// 不同语言需要翻译
console.log(requiresTranslation('en-US', 'es-ES')); // true
console.log(requiresTranslation('en-US', 'fr-FR')); // true

// 相同语言不需要翻译
console.log(requiresTranslation('en-US', 'en-US')); // false
console.log(requiresTranslation('en-US', 'en-GB')); // false

// 使用已批准的 locales 过滤器
const approved = ['en-US', 'es-ES', 'fr-FR'];
console.log(requiresTranslation('en-US', 'it-IT', approved)); // false(未在批准列表中)
console.log(requiresTranslation('en-US', 'es-ES', approved)); // true(已批准且与源语言不同)

备注

  • 遵循已批准的 locale 约束
  • 当目标不在已批准列表中时,返回 false
  • 支持自定义 locale 映射

后续步骤

这份指南怎么样?

requiresTranslation