演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。 Co-authored-by: Cursor <cursoragent@cursor.com>
23 lines
894 B
TypeScript
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
|
|
}
|