diff options
Diffstat (limited to 'packages/bank/src/i18n/index.tsx')
-rw-r--r-- | packages/bank/src/i18n/index.tsx | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/packages/bank/src/i18n/index.tsx b/packages/bank/src/i18n/index.tsx index 0694892..9882525 100644 --- a/packages/bank/src/i18n/index.tsx +++ b/packages/bank/src/i18n/index.tsx @@ -49,9 +49,9 @@ function toI18nString(stringSeq: ReadonlyArray<string>): string { let s = ''; for (let i = 0; i < stringSeq.length; i++) { s += stringSeq[i]; - if (i < stringSeq.length - 1) { + if (i < stringSeq.length - 1) s += `%${i + 1}$s`; - } + } return s; } @@ -64,9 +64,9 @@ interface TranslateSwitchProps { function stringifyChildren(children: ComponentChildren): string { let n = 1; const ss = (children instanceof Array ? children : [children]).map((c) => { - if (typeof c === 'string') { + if (typeof c === 'string') return c; - } + return `%${n++}$s`; }); const s = ss.join('').replace(/ +/g, ' ').trim(); @@ -97,24 +97,24 @@ function getTranslatedChildren( const placeholderChildren = Array<ComponentChild>(); for (let i = 0; i < childArray.length; i++) { const x = childArray[i]; - if (x === undefined) { + if (x === undefined) continue; - } else if (typeof x === 'string') { + else if (typeof x === 'string') continue; - } else { + else placeholderChildren.push(x); - } + } const result = Array<ComponentChild>(); - for (let i = 0; i < tr.length; i++) { - if (i % 2 == 0) { + for (let i = 0; i < tr.length; i++) + if (i % 2 == 0) // Text result.push(tr[i]); - } else { + else { const childIdx = Number.parseInt(tr[i], 10) - 1; result.push(placeholderChildren[childIdx]); } - } + return result; } @@ -154,18 +154,18 @@ export function TranslateSwitch({ children, target }: TranslateSwitchProps) { let singular: VNode<TranslationPluralProps> | undefined; let plural: VNode<TranslationPluralProps> | undefined; // const children = this.props.children; - if (children) { + if (children) (children instanceof Array ? children : [children]).forEach( (child: any) => { - if (child.type === TranslatePlural) { + if (child.type === TranslatePlural) plural = child; - } - if (child.type === TranslateSingular) { + + if (child.type === TranslateSingular) singular = child; - } + }, ); - } + if (!singular || !plural) { console.error('translation not found'); return h('span', {}, ['translation not found']); |