replace language text by icon

This commit is contained in:
dong.nguyen committed 2026-10-17 23:59:58 +07:00
1 parent c95f7b09d1
commit df65f4c774
11 files changed
+126 -65

No files matched your search

+34 -33
View File
@@ -42,13 +42,14 @@ Add full English/Vietnamese bilingual support to the portfolio. Users can toggle
| 18 | Update `ContactPage.tsx` (heading, labels) | 1 | ✅ Completed |
| 19 | Update `profile.ts` (fix tagline to VI) | 1 | ✅ Completed |
| 20 | Update `skills.ts` (add `titleEn` to skillGroups) | 1 | ✅ Completed |
| 21 | Add `.lang-toggle` CSS styles | 1 | ✅ Completed |
| 21 | Add `.lang-toggle` CSS styles | 1 | ✅ Completed — superseded 2026-10-17 by row 28 |
| 22 | **Phase 1 Complete** | | ✅ Completed |
| 23 | Create `src/i18n/useLocaleData.ts` (API fetch + fallback) | 2 | ⬜ Pending |
| 24 | Update all components to use `useLocaleData()` | 2 | ⬜ Pending |
| 25 | Remove `src/i18n/strings.ts` | 2 | ⬜ Pending |
| 26 | Remove `src/i18n/useField.ts` | 2 | ⬜ Pending |
| 27 | **Phase 2 Complete** | | ⬜ Pending |
| 28 | Language control → icon-only wireframe (globe / flag outline), `.lang-toggle` CSS deleted — 2026-10-17 | 1 | ✅ Completed |
## Current State Analysis
@@ -412,43 +413,42 @@ export function useLocaleData() {
---
## CSS
## Language Control — icon rendering (2026-10-17)
### Language Toggle Button
Supersedes the text-glyph design this spec first specified — `{lang === 'en' ? 'VI' : 'EN'}` in
`nav-control lang-toggle`, plus the `.lang-toggle` block that moved to `src/App.css` and is now
deleted. Both renderings are icon-only.
```css
/* src/index.css */
.lang-toggle {
display: flex;
align-items: center;
gap: 4px;
padding: 6px 10px;
border: 1px solid var(--border);
border-radius: 6px;
background: var(--bg-surface);
color: var(--text-primary);
cursor: pointer;
font-size: 13px;
font-weight: 500;
transition: all 0.2s ease;
}
Both icons are line drawings. The filled first pass (red `#da251d` field, `#ff0` star, scaled from
the Wikimedia flag SVG) was redrawn as a wireframe the same day on the owner's request, then re-cut
twice more the same day: band 21×14 → 21×16 → 21×17.5 to follow the globe's footprint, mullet r=4.2
at 2px → r=3.6 at 1.5px.
.lang-toggle:hover {
border-color: var(--accent);
color: var(--accent);
}
`src/components/ui/LanguageIcon.tsx` draws one 20×20 icon per language:
.lang-toggle .lang-label {
text-transform: uppercase;
letter-spacing: 0.5px;
}
| Language | Drawing | Stroke |
|---|---|---|
| `en` | globe: circle r=10, equator `M2 12h20`, meridian ellipse rx=4 ry=10 | `currentColor`, 2px, round joins — follows `.nav-control:hover`'s accent, like the mode toggle |
| `vi` | flag outline: 21×17.5 band (`rx=2`) at 1.5/3.25 — drawn 23×19.5 against the globe's 22×22; the width is already at the limit (the globe's own stroke spans 1..23), so every further size step has to come from height, and height drags the constitutional 2:3 to 1.2; the mullet centred at (12, 12) stays under the flag's own 0.6 × band-height construction — radius 3.6, drawn ≈ 8.3 units ≈ 36% × 41% of the band — traced as its concave decagon rather than a self-crossing pentagram | `currentColor`, no fills: band 2px round joins; star 1.5px round joins. 2px ink at r=3.6 closes the inner pentagon into a blob (the gap is 2(0.309·R − strokeWidth/2)), and miter joins throw a spike 3.24 × strokeWidth/2 past each 36° tip, drawing the star larger than its own radius |
.lang-toggle .lang-icon {
width: 16px;
height: 16px;
opacity: 0.7;
}
```
**Bar** (`src/components/layout/Navigation.tsx`): `nav-control lang-toggle` shows the language it
switches TO — the same contract the old glyph had.
| Attribute | Source |
|---|---|
| `aria-label` | `strings.nav.langSwitch[lang]` — `Switch language` / `Đổi ngôn ngữ` |
| `title` | `strings.nav.switchTo[lang]` + the target's `langEn` / `langVi` — `Switch to Tiếng Việt` / `Chuyển sang English` |
| Content | `<LanguageIcon lang={targetLang} />`, `aria-hidden="true"` + `focusable="false"` |
| CSS | `.nav-control` chrome only; `.lang-toggle` carries no rules of its own — it marks the button in the DOM |
**Sheet** (`src/components/layout/MobileMenu.tsx`): the Language row's two options are
`.mobile-menu-icon-option` — the 44px icon-only square the Theme color row uses. The Mode row keeps
`.mobile-menu-segment-option`, because its options are words. Each option carries `aria-pressed` and
its own-language name in `aria-label` and `title`: an icon alone cannot say which language it is.
`langEn` / `langVi` stay flat `{en, vi}` records. A nested `langName: { en: …, vi: … }` record inside
`strings.nav` was tried and rejected: `strings.nav[navKey][lang]`, the lookup both components use for
nav labels, would then carry an object in its value union and `tsc` rejects it as a `ReactNode`.
---
@@ -459,6 +459,7 @@ export function useLocaleData() {
- [ ] Testing: Verify all strings render correctly in both languages
- [ ] Testing: Verify language toggle persists across page navigation
- [ ] Testing: Verify language preference persists across sessions (localStorage)
- [x] Testing: 2026-10-17 icon swap — throwaway SSR render of `Navigation` + `MobileMenu` at `lang=en` and `lang=vi`: bar icon equals the target language's icon, `aria-label`/`title` translated, sheet options icon-only with `aria-pressed`, Mode row still word-based — 24/24 PASS, script deleted after the run. Visual pass left to the owner's browser (repo rule §5).
---
@@ -327,7 +327,7 @@ langEn: {en: 'English', vi: 'English'},
langVi: {en: 'Tiếng Việt', vi: 'Tiếng Việt'},
```
`langEn` / `langVi` carry the same value in both locales on purpose: a language option is named in its own language, so a reader who cannot read English can still find "Tiếng Việt". The bar keeps the short `VI` / `EN` codes (`Navigation.tsx:84`); the sheet uses full names because it has the width.
`langEn` / `langVi` carry the same value in both locales on purpose: a language option is named in its own language, so a reader who cannot read English can still find "Tiếng Việt". The bar keeps the short `VI` / `EN` codes (`Navigation.tsx:84`); the sheet uses full names because it has the width. **Superseded 2026-10-17:** both renderings are icons now — the bar shows the target language's globe/flag, the sheet's Language row shows both — and the own-language names moved into `aria-label` / `title`. See `spec-v3-i18n.md` §Language Control.
New block, replacing `strings.common.socialAriaLabels` (`strings.ts:106-110`), which is **deleted** — it already holds these three values and is consumed by nothing today:
@@ -228,7 +228,7 @@ No new state, no new handler, no `initial` prop (the component mounts closed, so
### Step 5 — nothing else
`Navigation.tsx`, `MobileMenu.tsx`, `strings.ts`, `useClickOutside.ts`, `palettes.ts` and the language control are not touched. No CSS class is added or removed; `.lang-toggle` (`src/App.css:119-123`) stays live.
`Navigation.tsx`, `MobileMenu.tsx`, `strings.ts`, `useClickOutside.ts`, `palettes.ts` and the language control are not touched. No CSS class is added or removed; `.lang-toggle` (`src/App.css:119-123`) stays live. **Superseded 2026-10-17:** the language control became icon-only line art (globe / flag outline, `src/components/ui/LanguageIcon.tsx`) and its `.lang-toggle` rules were deleted, so the bar's three controls are all icon-only; §2.1 facts 1–3 describe the pre-change baseline. See `spec-v3-i18n.md` §Language Control.
---
+1 -1
View File
@@ -48,7 +48,7 @@ Reading bands used: 45-75 characters (Bringhurst), 38-80 (Butterick). Before: 11
1. **Font: admit `system-ui`.** `--sans` becomes `system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif`. No webfont is loaded; the Source Sans 3 woff2 files stay in `public/fonts/` because `scripts/generate-resume.ts` reads them from disk for the PDF. (User's call: keep the current look rather than restyle the whole site.)
2. **Scale tokens** in `:root`: `--text-body: 18px`, `--text-lede: 20px`, `--text-meta: 15px`, `--leading-body: 1.65`, `--measure-prose: 600px`, `--measure-page: 680px` (added in the second pass, §3.10). They live in `:root` only — sizes do not differ between dark and light, so they are not duplicated in the light block or the media bridge.
3. **Reuse `.prose`** (`App.css`, previously defined and never rendered by any component) as the prose system instead of inventing a second convention.
4. **Role sizes.** Body copy 18px/1.65 everywhere a paragraph is the main content; lead paragraphs 20px/1.55; dense secondary copy (timeline bullets, achievement context and impact, expertise skill lists, card summaries, contact sub-labels) 15px/1.65. Literal 12-14px stays reserved for chrome: `.tag`, `.badge`, `.achievement-metric`, `.footer-text`, `.footer-link`, `.timeline-duration`, `.project-card-cta`, `.lang-toggle`, `pre`.
4. **Role sizes.** Body copy 18px/1.65 everywhere a paragraph is the main content; lead paragraphs 20px/1.55; dense secondary copy (timeline bullets, achievement context and impact, expertise skill lists, card summaries, contact sub-labels) 15px/1.65. Literal 12-14px stays reserved for chrome: `.tag`, `.badge`, `.achievement-metric`, `.footer-text`, `.footer-link`, `.timeline-duration`, `.project-card-cta`, `pre`. (`.lang-toggle` was on that list until 2026-10-17, when the language control became an icon and its glyph step was deleted.)
5. **Heading sizes**: `h3` 24 → **21px**, and `h4` 18 / `h5` 16 / `h6` 15 made explicit (they previously fell back to 16px). `h1`/`h2` clamps and the global `h1-h6 { line-height: 1.2 }` are untouched.
6. **Paragraph rhythm lives only inside `.prose`** (`.prose p { margin-bottom: 1em }`, `:last-child` 0). The global `p` keeps `margin: 0` from the reset, so hero, cards, section subtitles and contact tiles are unaffected.
7. **Headings carry their own top margin** (`.subheading { margin-top: 32px }`, `.prose h3 { margin-top: 1.5em }`, `.philosophy-quote h3 { margin-top: 0 }`); lead paragraphs carry no bottom margin. Sibling margins collapse, so each gap is a single value rather than a sum.