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
javascript internationalization API
Search
Taketoshi Aono(青野健利 a.k.a brn)
August 27, 2019
Programming
0
790
javascript internationalization API
EcmascriptのInternationalization APIについて
Taketoshi Aono(青野健利 a.k.a brn)
August 27, 2019
Tweet
Share
More Decks by Taketoshi Aono(青野健利 a.k.a brn)
See All by Taketoshi Aono(青野健利 a.k.a brn)
document.write再考
brn
6
2.9k
Parsing Javascript
brn
12
9k
JSON & Object Tips
brn
1
400
CA 1Day Youth Bootcamp for Frontend LT
brn
0
790
Modern TypeScript
brn
2
750
javascript - behind the scene
brn
3
680
tc39 proposals
brn
0
780
プロダクト開発とTypeScript
brn
8
2.8k
React-Springでリッチなアニメーション
brn
1
600
Other Decks in Programming
See All in Programming
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
subpath importsで始めるモック生活
10tera
0
300
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
310
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1k
Realtime API 入門
riofujimon
0
150
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
CSC509 Lecture 12
javiergs
PRO
0
160
AWS IaCの注目アップデート 2024年10月版
konokenj
3
3.3k
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
470
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
Featured
See All Featured
Git: the NoSQL Database
bkeepers
PRO
427
64k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
A better future with KSS
kneath
238
17k
Navigating Team Friction
lara
183
14k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.2k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Docker and Python
trallard
40
3.1k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
Transcript
Javascript Internationalization API
Name !CSO 5BLFUPTIJ"POP੨݈ར Occupation 'SPOUFOE%FWFMPQFS1SPEVDU0XOFS Company $ZCFSBHFOU"EUFDI4UVEJP"*.FTTFOHFS OSS $POUSJCVUPSPG7
About IUUQJOGPCODI
&DNB &DNB͕&DNBͱͯ͠*OUFSOBUJPOBMJ[BUJPO"1*ͷ༷ࡦఆΛߦ͍ͬͯΔ &DNBͰ͋Δ&DNBTDSJQU +BWBTDSJQU ͕&DNBΛแ͓ͯ͠Γ &DNBTDSJQUଆʹJOͷ࣮͕ఏڙ͞ΕΔ ͪͳΈʹ+40/&DNBͰఆٛ͞Ε͓ͯΓɺ&DNBʹแ͞Ε͍ͯΔ
*OUM *OUFSOBMJ[BUJPO"1**OUMͱ͍͏άϩʔόϧΦϒδΣΫτΛެ։͓ͯ͠Γ ͦͷΦϒδΣΫτܦ༝Ͱ֤छ"1*ʹΞΫηε͢Δ͜ͱ͕Ͱ͖Δ ࠓͦͷத͔Βදతͳͭͷ"1*Λհ
*OUM$PMMBUPS
*OUM$PMMBUPS *OUM$PMMBUPSओʹจࣈྻൺֱΛߦ͏ͨΊͷ"1* ֤MPDBMFΛؾʹ͠ͳ͕Β6OJDPEFʹجͮ͘ෳࡶͳจࣈൺֱΛߦͬͯ͘ΕΔ
console.log(new Intl.Collator().compare('a', ‘c')); // → a negative value console.log(new Intl.Collator().compare('c',
'a')); // → a positive value console.log(new Intl.Collator().compare('a', 'a')); // → 0
new Intl.Collator('gr',{sensitivity: ‘base'}) .compare(‘ς', 'σ') // → 0 // ΪϦγϟޠͷγάϚจͱจதͰจࣈίʔυ͕ҟͳΔ
// CollatorΛ͏ͱɺsensitivityͷࢦఆͰൺֱͷৄࡉ Λઃఆͯ͜͠ͷΑ͏ͳෳࡶͳൺֱ͕Ͱ͖Δ
*OUM/VNCFS'PSNBU
*OUM/VNCFS'PSNBU *OUM/VNCFS'PSNBUMPDBMFʹԠͨ͡ͷॲཧΛߦ͏"1* EFDJNBMͱDVSSFODZʢ͓ۚʣͷͭʹରԠ
var number = 123456.789; // υΠπͰΧϯϚΛখɺϐϦΦυΛઍ୯Ґͷ۠Γʹ༻͍Δ console.log(new Intl.NumberFormat('de-DE').format(number)); // →
123.456,789 // ΠϯυͰthousands/lakh/crore۠Γ͕༻͍Δ console.log(new Intl.NumberFormat('en-IN').format(number)); // → 1,23,456.789 // nu֦ுΩʔʹΑΓࣈͳͲͷ൪߸ํ͕ࣜ͑Δ console.log(new Intl.NumberFormat(‘zh-Hans-CN-u-nu-hanidec') .format(number)); // → Ұೋࡾ,࢛ޒ.ࣣീ
var number = 123456.789; // ௨՟ϑΥʔϚοτΛ༻͍Δ console.log(new Intl.NumberFormat(‘de-DE', { style:
'currency', currency: 'EUR' } ).format(number)); // → 123.456,79 € console.log(new Intl.NumberFormat(‘ja-JP', { style: 'currency', currency: 'JPY' } ).format(number)); // → ˇ123,457
*OUM1MVSBM3VMFT
*OUM/VNCFS'PSNBU ୯ޠͷෳܗͷॲཧΛߦ͏"1*
var pr = new Intl.PluralRules('en-US'); pr.select(0); // → ‘other’ ෳܗ
pr.select(1); // → ‘one' ୯ܗ pr.select(2); // → ‘other' ෳܗ
const type = pr.select(count); const wordIndices = {'other': 'dogs', 'one':
'dog'}; const verbIndices = {'other': 'are', 'one': 'is'}; console.log( `Your ${indices[type]} ${verbIndices[type]} cute.` ) // count === 1 Your dog is cute. // count === 0 || count > 1 Your dogs are cute.
const ordIndices = { 'one': 'st', 'two': 'nd', 'few': 'rd',
'other': 'th' } const pr = new Intl.PluralRules('en-US', {type: ‘ordinal'} ); const ord = pr.select(3); // → few console.log(`3${ordIndices[ord]}`); // → 3rd
*OUM%BUFUJNF'PSNBU
*OUM%BUFUJNF'PSNBU MPDBMFʹԠͨ͡ͱ࣌ࠁͷॲཧΛߦ͏"1*
new Intl.DateTimeFormat('ja-JP', { year: 'numeric', month: 'long', day: 'numeric', hour:
'numeric', minute: 'numeric', second: 'numeric', hour12: false} ).format(new Date()) // → 20198݄27 16:47:50
new Intl.DateTimeFormat('ja-JP', { month: 'long', day: 'numeric', hour: 'numeric', hour12:
false} ).format(new Date()) // → 8݄27 16࣌
*OUM%BUFUJNF'PSNBU GPSNBU5P1BSUTͱ͍͏ϝιουΛ͏͜ͱͰಠࣗͷϑΥʔϚοτ࣮ݱͰ͖ Δ
new Intl.DateTimeFormat('ja-JP', { year: 'numeric', month: 'long', day: 'numeric', hour:
'numeric', minute: 'numeric', second: 'numeric', hour12: false} ).formatToParts(new Date())
[ { "type": "year", "value": "2019" }, { "type": "literal",
"value": "" }, { "type": "month", "value": "8" }, { "type": "literal", "value": "݄" }, { "type": "day", "value": "27" }, { "type": "literal", "value": " " }, { "type": "hour", "value": "16" }, { "type": "literal", "value": ":" }, { "type": "minute", "value": "57" }, { "type": "literal", "value": ":" }, { "type": "second", "value": "38" } ]
·ͱΊ *&͔Β͑ΔͷͰੋඇ͓ࢼ͠Λ