feat(i18n): add bilingual() display helper

This commit is contained in:
Chris Chen
2026-05-29 22:02:50 -07:00
parent fef3b76a31
commit a99755a5db
2 changed files with 26 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
import { bilingual } from './bilingual';
describe('bilingual', () => {
it('joins English and Chinese with a slash, no spaces', () => {
expect(bilingual('Worship', '敬拜')).toBe('Worship/敬拜');
});
it('returns English only when Chinese is null', () => {
expect(bilingual('Zelle', null)).toBe('Zelle');
});
it('returns English only when Chinese is undefined', () => {
expect(bilingual('PayPal')).toBe('PayPal');
});
it('returns English only when Chinese is an empty string', () => {
expect(bilingual('Other', '')).toBe('Other');
});
});
+7
View File
@@ -0,0 +1,7 @@
/**
* Display-only bilingual label: English first, Chinese second, joined by '/'
* with no spaces. Falls back to English alone when no Chinese is provided.
* Does NOT alter stored values — for display binding only.
*/
export const bilingual = (en: string, zh?: string | null): string =>
zh ? `${en}/${zh}` : en;