Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
React 多言語対応
Search
tatsuaki
October 31, 2023
Programming
390
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
React 多言語対応
2023/11/11 ENGINE登壇資料
tatsuaki
October 31, 2023
Other Decks in Programming
See All in Programming
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
220
ChromeでローカルLLM
ryu1013
0
140
Rでドレミ/Do-Re-Mi_with_R
florets1
0
130
Domain-Driven Transformation
hschwentner
2
2.3k
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
440
AIに “答え“を書かせるのを やめてみた
___akari11
0
120
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
220
Agentic Software Factoryに、すごく賢いIF文を。 / super smart IF statement into the Agentic Software Factory.
rkaga
8
2.2k
ActionController meets Protocol Buffers
sorah
0
550
Optunaを作ったときにやりたかったこと、その後 (2026/10/16, Optuna Meetup #3)
iwiwi
1
440
Findy - エンジニア向け会社紹介/Findy Company Deck
findyinc
6
400k
AIで開発が速くなった先で、開発チームは何を目指すか
shihochan
1
1.6k
Featured
See All Featured
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
520
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
530
WENDY [Excerpt]
tessaabrams
14
40k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
430
Building Adaptive Systems
keathley
44
3.3k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
570
GitHub's CSS Performance
jonrohan
1033
470k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
550
Designing for Performance
lara
612
70k
The Limits of Empathy - UXLibs8
cassininazir
2
720
Practical Orchestrator
shlominoach
192
12k
Visualization
eitanlees
153
17k
Transcript
React 多言語対応 プロダクトデザイン部 松岡龍紀
目次 ▼ Webサイトにおける「多言語化対応」とは ▼ Reactで多言語化対応する術 ▼ やってみる
Webサイトにおける「多言語化対応」とは
Webサイト上のコンテンツを自国以外の言語を利用して、 外国人向けにフォーマット すること。 また、多言語対応には様々なポイントや課題があるが、その中で下記が挙げられる。 • ニーズに応じて取捨選択 • 技術的にコストがかかると同時に予算工数にも影響が出てくる懸念 英語 日本語
Reactで多言語対応する術 ※これから紹介するのは、あくまで一例で他にもやり方はありま す。
• Format.JS • react-i18next
Format.JS • <Formatted**> コンポーネントを使用して多言語化を実現する。 • フォーマット機能も提供されている。 こんにちは 2016年4月05日
react-i18next • ビルトインされているメソッドを使用する。 • 記述がシンプル。 • 併用できるパッケージが多数ある。 こんにちは
やってみる
ディレクトリ構成
ディレクトリ構成 後々使用するメソッドで型を得るためにアンビ エントで型を定義。 言語管理するためのjsonファイルと、設定ファ イル。
use 使用するパッケージ (プラグイン)を登録 lng デフォルトで使用する言語 debug デバッグ情報表示有無 defaultNS 使用するネームスペース。複数の言語ファイルを使用 するときなどに活用。
resources 翻訳に使用する元ファイルを登録。 etc https://www.i18next.com/overview/configuration-options config.ts
テキストにアクセスするためのkeyと翻訳に使用したいテキストをvalueに設定。 例では、言語ごとにファイルを分けて、中身をコンポーネント名で分割している。 ネームスペースをうまく使えば、コンポーネントごとにファイルを分割できたりする。 json 日本語 英語
useTranslationからtメソッドを取得。 翻訳対象の要素にtメソッドをかまして多言語 化する。 tメソッドの引数にjsonファイルで定義したkey でアクセスし対象要素を表示できる。 ComponentA.tsx
アンビエントで定義した型ファイルを用 意すれば、tメソッドに型が適用される。 jsonに定義されていない内容にアクセス すると型エラーになると同時にコード補 完もされるのでケアレスミスの回避にもつ ながる。 ComponentA.tsx
ルートコンポーネントでconfigファイルを importすることでi18nを適用できる。 i18nextから生えているchangeLanguage メソッドを使用してボタン切り替えで言語 切替をできる。 App.tsx
https://github.com/bita-matsuoka/react-i18next 今回用意したコード
• i18next-browser-languageDetector ブラウザの言語設定を自動判別してその言語を適用させるパッケージ。 • i18next-http-backend ファイルシステムから言語ファイルをロードするためのパッケージ。 • locize 言語ファイルを管理できるプラットフォーム。 エンジニアが関わらずとも翻訳チームだけで運用可能にできたり、文言修正のコストを削減できた
りする。 etc … https://www.i18next.com/overview/plugins-and-utils 有用なパッケージ
参考文献 • react-i18next https://react.i18next.com/ • react-18next sample code https://github.com/i18next/react-i18next/tree/master/example/react-typescript • Format.JS https://formatjs.io/