Skip to content

feat:Create LanguageContext to eliminate prop drilling for locale switching#304

Merged
zigzagdev merged 38 commits intomainfrom
chore/create-language-context
May 2, 2026
Merged

feat:Create LanguageContext to eliminate prop drilling for locale switching#304
zigzagdev merged 38 commits intomainfrom
chore/create-language-context

Conversation

@zigzagdev
Copy link
Copy Markdown
Owner

@zigzagdev zigzagdev commented May 2, 2026

Content

Implement language (ja/en) switching via useContext, replacing prop drilling
across components with a centralized LanguageContext.

Changes

  • Add LanguageContext and LanguageProvider
  • Add useLang() custom hook for consuming locale state
  • Replace prop-based language passing with useLang() calls across components
  • Add locale toggle on heritage detail view

Motivation

Language state was being passed down through multiple component layers.
Centralizing it in a context makes each component's interface cleaner
and removes unnecessary props from intermediate components.

zigzagdev and others added 30 commits April 29, 2026 17:13
Introduce a feature-level LocaleProvider that derives the active locale
from the ?lang= query string and exposes setLocale/toggleLocale through
useLocale, mirroring the existing BreadcrumbProvider layout. Mount the
provider in AppRoutes so downstream containers can consume locale
context instead of resolving it inline.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
feat: add LocaleProvider with URL synced locale state
feat: add LocaleProvider with URL synced locale state
Drop the named LocaleContextType alias and pass the shape directly to
createContext, keeping the .tsx file free of named type declarations.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Drop the URL-derived locale plumbing in WorldHeritageDetailContainer
and the locale/toggleLocale props on HeritageDetailLayout, HeritageHero,
and HeritageOverViewSection. Each component now reads locale from
useLocale(), so the container only forwards item and the detail tree
no longer prop-drills locale state.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The earlier consumer migration removed the locale prop from
HeritageOverViewSection but left the call site still passing it,
breaking the CI typecheck.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…-detail

Refactor/use locale context in detail
Introduce per-locale UI string dictionaries under src/locals/{en,ja}/ui.json
and a useText hook in src/shared/locale that picks the dictionary off the
active locale from useLocale. Components can now read UI labels from a
single typed source instead of hard-coding English strings.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Pull static labels (DANGER, No image, Heritage Category, Criteria,
View details, No overview available) through useText so the card
follows the active locale, and fix the title fallback so it returns
item.name in EN mode instead of always favouring heritageNameJp.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Pull static labels (Region, Category, Year Inscribed, Criteria,
Description, Maps, Gallery, Overview, View on UNESCO) through useText
in HeritageDetailLayout, HeritageHero, HeritageOverViewSection, and
HeritageSidebar so the detail screen follows the active locale.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…apping

Chore/top component context wrapping
Make toWorldHeritageVm / toWorldHeritageDetailVm / toHeritageSearchResultVm
take a locale argument and resolve title, subtitle, country, and the new
displaySubName / displayDescription fields per locale. Hooks and the search
results container now read locale via useLocale and feed it to the mappers,
so English locale no longer falls back to Japanese strings. Also rename
to-world-heritage-detail-vm-test.ts to .test.ts so Jest actually picks it up.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
HeritageCard, HeritageHero, and HeritageOverviewSection now read
title / displaySubName / displayDescription off the VM instead of
switching on locale and re-deriving the label themselves. The locale
toggle and the LocaleProvider's own locale check are unaffected.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds heritageData, country, stateParty, endangered, propertyArea,
bufferZone, latitude, longitude, yes, and no to both en and ja
ui dictionaries so the sidebar's metadata rows can be localized.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Swap hardcoded English labels (Country, Category, Region, Yes/No, etc.)
and the "Heritage Data" heading for keys read from useText, so the
sidebar follows the active locale instead of staying English-only.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Rename two ja labels to match the wording used by mainstream Japanese
heritage sites (Mynavi etc.):
- country: 国 → 保有国
- category: カテゴリ → 分類

en labels are unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Drop the inline REGION_LABELS / CATEGORY_LABELS constants and pull every
visible string (chip headings, placeholders, aria-labels, the search
button) from useText. The empty option falls back to text.all; the
other options reuse the existing categoryLabels / regionLabels dicts.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
zigzagdev and others added 8 commits May 2, 2026 13:36
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…onents

Pull TopPage's title row, items grid, and pagination block out into
TopPageTitleBar, HeritageList, and TopPagePagination. TopPage becomes a
thin slot-based shell taking { titleBar, header, content, pagination }
as ReactNodes; the container builds each subcomponent and wires them in.
The 13-field TopPage Props collapses to four ReactNode slots inlined
on the signature, so the named type is gone. Test mocks for TopPage and
its callers are retargeted at the new subcomponents.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Pull the locale switch button (the flag toggle) out into a shared
LocaleToggle component under shared/locale and use it in both
HeritageDetailLayout and TopPageTitleBar instead of duplicating the
inline button. The detail layout no longer needs useLocale directly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Add appTitle and appTagline keys to en/ja ui dictionaries and read them
in TopPageTitleBar via useText, replacing the hardcoded "World Heritage"
heading and "Learn by searching..." subheading.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Refactor: `locale-aware VM`s, `dictionary-driven view`s, and `TopPage` decomposition
@zigzagdev zigzagdev changed the title Chore/create language context Create language context May 2, 2026
@zigzagdev zigzagdev self-assigned this May 2, 2026
@zigzagdev zigzagdev linked an issue May 2, 2026 that may be closed by this pull request
@zigzagdev zigzagdev changed the title Create language context feat:Create LanguageContext to eliminate prop drilling for locale switching May 2, 2026
Copy link
Copy Markdown
Owner Author

@zigzagdev zigzagdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zigzagdev zigzagdev merged commit af4023d into main May 2, 2026
1 check passed
@zigzagdev zigzagdev deleted the chore/create-language-context branch May 2, 2026 06:54
@zigzagdev zigzagdev linked an issue May 3, 2026 that may be closed by this pull request
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor: Introduce LanguageContext to eliminate prop drilling Type cleanup and LanguageContext introduction

1 participant