Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
実行場所を意識させない i18n API を作った話
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
ANDPAD inc
August 21, 2026
Programming
56
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
実行場所を意識させない i18n API を作った話
柿森 隆生
2026 年 8 月 21 日
React Tokyo ミートアップ #19
ANDPAD inc
August 21, 2026
More Decks by ANDPAD inc
See All by ANDPAD inc
Go 1.27 における memory allocation の高速化
andpad
0
380
言語を使う側から、作る側へ。 自作 Lisp で得た新たな気づき。
andpad
0
180
OS アップデート対応の取り組み方がもっと共有されてほしい
andpad
0
140
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
560
ANDPAD Ruby sponsor session in RubyKaigi 2026
andpad
0
260
AWS WAFの運用を地道に改善し、自社で運用可能にするプラクティス
andpad
2
1.3k
アプリから 360 度カメラ「RICOH THETA」に接続して写真を撮影する
andpad
0
90
アンドパッドが提供する Drinks and Local Meals と Drinkup を大公開
andpad
0
160
建設DXを支えるANDPAD: 2025年のセキュリティの取り組みと卒業したいセキュリティ
andpad
0
620
Other Decks in Programming
See All in Programming
高専、大学編入、そして未踏へ〜プロダクト開発とキャリアの歩み - Technical College, University Transfer, and On to “Mitou” / My Journey in Product Development and Career
pkmiya
0
140
【DroidKaigi 2026】「アクセシビリティを利用するとき、 アクセシビリティもまたこちらを利用している」 〜マルウェアによる攻撃と防衛について〜
halunoyo
0
410
What We Talk About When We Talk About XP
m_seki
2
380
AI駆動開発にグラフDBを重ねてみた
satoshi256kbyte
2
750
私のClaude Code活用法 (個人開発編) - PHPerKaigi mini #4(2026/08/24)
panda_program
1
210
AIと壁打ちしながら進めるコスト管理
fufuhu
2
1.9k
Building an Out-of-Order CPU
latte72
0
710
Oxlintはいいぞ(続)
yug1224
1
550
信頼性の目標を誰も求めてない
shubox
0
490
バグを直したら useEffect が消えた
colorful12
3
840
Go × SIMDで高速化するベクトル検索 ~ルーフラインモデルでSIMDが効く境界を探れ! ~
po3rin
1
110
RSSとCodexを使ってX投稿自動化してみた
ochtum
0
110
Featured
See All Featured
WCS-LA-2024
lcolladotor
0
820
The Mindset for Success: Future Career Progression
greggifford
PRO
0
490
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
4.7k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.3k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
4
590
GitHub's CSS Performance
jonrohan
1033
470k
Context Engineering - Making Every Token Count
addyosmani
9
1.1k
Docker and Python
trallard
47
4.2k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
430
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.8k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
490
Transcript
実行場所を意識させないi18n APIを作った話 colocaleというOSSを作りました © 2026 ANDPAD All Rights Reserved. Confidential
自己紹介 | Speaker 柿森 隆生 GitHub | Urotea ポジション: TechLead(プロダクトのためになんでもやる人)
最近よく書いている言語: skills(言語なのか?) 趣味: LoL / OW © 2026 ANDPAD All Rights Reserved. Confidential 2
ただ表示する言葉を変えるだけのはずだった どの言語を表示するかの分岐はスコープ外とさせてください。 今回の話は言語ごとにラベルを入れ替えるだけの小さな部品の話です。 ラベルを日本語と英語で切り替えたい 該当のコンポーネントはサーバーコンポーネントからもクライアントからも使いたい next-intlのようなi18nライブラリは、サーバーとクライアントでAPIが分かれているので、コンポーネントが 動く場所を意識せざるを得ない さらにプラグインの追加やProviderの追加も必要になる ラベルを差し替えるだけなのに、なぜか設計の話になった。 ©
2026 ANDPAD All Rights Reserved. Confidential 3
動く場所を先に決めさせられる | next-intl の場合 'use client'; // ← これでサーバーから使えなくなる import
{ useTranslations } from 'next-intl'; export const ReportListItem = (props: Props) => { const t = useTranslations('report'); // ← サーバーでは getTranslations return ( <li> <span>{t('date')}:{props.date}</span> <span>{t('count', { count: props.count })}</span> </li> ); }; クライアントは useTranslations 、サーバーは getTranslations と関数が分かれる 加えて next.config へのプラグイン追加と、Provider がもう一段 © 2026 ANDPAD All Rights Reserved. Confidential 4
動く場所を意識させるAPIは再利用性を殺す 先の例のような小さな部品ほど、サーバーとクライアントの両方で使いたい なのにi18nのAPIが場所ごとに分かれていると、部品が動く場所に縛られる サーバーとクライアントで実行モデルが違うのは当然。問題はその違いをコンポーネント自身に意識させてい ること プラグインやProviderの追加も不要で、実行場所を意識せず、ラベルを差し替えるだけのAPIが欲しい © 2026 ANDPAD All
Rights Reserved. Confidential 5
単純に引数で渡す | colocale import { createTranslator, type Messages } from
'colocale'; import { reportItemTranslations } from './translations'; export const ReportListItem = (props: Props & { messages: Messages }) => { const t = createTranslator(props.messages, reportItemTranslations); return ( <li> <span>{t('date')}:{props.date}</span> <span>{t('count', { count: props.count })}</span> </li> ); }; 場所を知る責任が呼び出し側に移り、コンポーネントはどこでも動く 利用する辞書は translations.ts に置く: defineRequirement('report', ['date', 'count']) © 2026 ANDPAD All Rights Reserved. Confidential 6
代償とまだ解けていないこと Propsに messages が増える。いわゆるバケツリレー requirementを取り違えて絞ると、型は通るのに実行時にキーが足りない Messages 型がrequirementでパラメータ化されていないため 回避策はある: requirementを大きめの粒度で作ったり、requirementを省略して指定言語の全辞書を渡す(小 規模ならこれで十分)
宿題: 足りないキーをコンパイルエラーにする方法を探しています。心当たりのある方は教えてください。 © 2026 ANDPAD All Rights Reserved. Confidential 7
まとめ RSC時代に欲しかったのは、動く場所を知らなくていいi18n API Providerを捨てて引数で渡すだけで、同じコンポーネントがサーバーでもクライアントでも動く 副産物として、React以外でも同じ書き方が使える(Vueにも対応) colocale github.com/Urotea/colocale おまけ: 翻訳をYAMLで書いてJSONに変換するyamlocaleも公開しています(i18next /
react-intl / vue-i18n でも使えます) github.com/Urotea/yamlocale © 2026 ANDPAD All Rights Reserved. Confidential 8