| 1 | import type { ClaimType } from '../game/engine'; |
| 2 | import { useLang } from './lang'; |
| 3 | |
| 4 | /** |
| 5 | * Bilingual label: the Chinese term players call at the table, with the English |
| 6 | * underneath for anyone still learning it. Tile faces stay pure Chinese — those |
| 7 | * are the tiles themselves, not UI chrome. |
| 8 | * |
| 9 | * A table that reads only one of the two says so in the lobby, and this is |
| 10 | * where that choice lands: one span or the other, never neither. |
| 11 | */ |
| 12 | export function Bi({ zh, en, sub }: { zh: string; en: string; sub?: string }) { |
| 13 | const lang = useLang(); |
| 14 | return ( |
| 15 | <span className="bi"> |
| 16 | {lang !== 'en' && ( |
| 17 | <span className="zh" lang="zh-TW"> |
| 18 | {zh} |
| 19 | </span> |
| 20 | )} |
| 21 | {lang !== 'zh' && ( |
| 22 | <span className="en" lang="en"> |
| 23 | {en} |
| 24 | </span> |
| 25 | )} |
| 26 | {/* Tile names, near enough always — 五萬, 東風 — so it stays put. */} |
| 27 | {sub && <span className="bi-sub">{sub}</span>} |
| 28 | </span> |
| 29 | ); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Two lines of prose rather than a label: the hint paragraphs, which put the |
| 34 | * break between the languages instead of a middot. One of them in either of the |
| 35 | * single-language modes, and then there is nothing to break. |
| 36 | */ |
| 37 | export function BiText({ zh, en }: { zh: string; en: string }) { |
| 38 | const lang = useLang(); |
| 39 | if (lang === 'zh') return <>{zh}</>; |
| 40 | if (lang === 'en') return <>{en}</>; |
| 41 | return ( |
| 42 | <> |
| 43 | <span lang="zh-TW">{zh}</span> |
| 44 | <br /> |
| 45 | <span lang="en">{en}</span> |
| 46 | </> |
| 47 | ); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * The other bilingual shape in the app: the Chinese, with the English beside it |
| 52 | * in an <em> that the CSS shrinks and spaces — headings, field labels, the name |
| 53 | * on a switch. The <em> is the pairing, so in one language there is none. |
| 54 | */ |
| 55 | export function BiEm({ zh, en }: { zh: string; en: string }) { |
| 56 | const lang = useLang(); |
| 57 | if (lang === 'zh') return <>{zh}</>; |
| 58 | if (lang === 'en') return <>{en}</>; |
| 59 | return ( |
| 60 | <> |
| 61 | <span lang="zh-TW">{zh}</span> |
| 62 | <em lang="en">{en}</em> |
| 63 | </> |
| 64 | ); |
| 65 | } |
| 66 | |
| 67 | export const CLAIM_LABEL: Record<ClaimType, [string, string]> = { |
| 68 | hu: ['胡', 'Win'], |
| 69 | kong: ['槓', 'Kong'], |
| 70 | pung: ['碰', 'Pung'], |
| 71 | chow: ['吃', 'Chow'], |
| 72 | }; |