Files
gsfdc/demo-dify/dify/packages/tooling/i18n-plurals.ts
T
wuzilongandCursor 6519682885 chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-18 13:59:25 +08:00

23 lines
894 B
TypeScript

/** Match locale-specific plural forms to the English family's `other` entry. */
export function getTranslationSourceKey(
sourceKeys: ReadonlySet<string>,
key: string,
language: string,
): string | undefined {
if (sourceKeys.has(key)) return key
const match = /^(.*)_(zero|one|two|few|many|other)$/.exec(key)
if (!match) return undefined
const [, base, category] = match
if (!base || !category) return undefined
const ordinal = base.endsWith('_ordinal')
const categories: readonly string[] = new Intl.PluralRules(language, {
type: ordinal ? 'ordinal' : 'cardinal',
}).resolvedOptions().pluralCategories
// i18next supports an explicit zero override even when CLDR has no zero category.
if (!categories.includes(category) && !(category === 'zero' && !ordinal)) return undefined
const other = `${base}_other`
return sourceKeys.has(other) ? other : undefined
}