์ฝ˜ํ…์ธ  ๋Œ€ํ‘œ ์ด๋ฏธ์ง€ - ๐ŸŒ ์ž๋ฐ” ๊ตญ์ œํ™”์™€ ResourceBundle์„ ํ™œ์šฉํ•œ ๋‹ค๊ตญ์–ด ์ง€์› ์™„๋ฒฝ ๊ฐ€์ด๋“œ

๐ŸŒ ์ž๋ฐ” ๊ตญ์ œํ™”์™€ ResourceBundle์„ ํ™œ์šฉํ•œ ๋‹ค๊ตญ์–ด ์ง€์› ์™„๋ฒฝ ๊ฐ€์ด๋“œ

๊ธ€๋กœ๋ฒŒ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ฐœ๋ฐœ์˜ ํ•„์ˆ˜ ๊ธฐ์ˆ ์„ ์นœ๊ตฌ์ฒ˜๋Ÿผ ์‰ฝ๊ฒŒ ๋ฐฐ์›Œ๋ณด์ž! ๐Ÿš€

Java Application ResourceBundle English messages_en.properties ํ•œ๊ตญ์–ด messages_ko.properties ๆ—ฅๆœฌ่ชž messages_ja.properties ไธญๆ–‡ messages_zh.properties ๐ŸŒ ๐Ÿ’ฌ

๐ŸŽฏ ์™œ ๋‹ค๊ตญ์–ด ์ง€์›์ด ํ•„์š”ํ• ๊นŒ?

์•ˆ๋…•! ์˜ค๋Š˜์€ ์ž๋ฐ”๋กœ ๊ธ€๋กœ๋ฒŒ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋งŒ๋“ค ๋•Œ ๊ผญ ํ•„์š”ํ•œ ๊ตญ์ œํ™”(Internationalization, i18n)์™€ ์ง€์—ญํ™”(Localization, l10n)์— ๋Œ€ํ•ด ์ด์•ผ๊ธฐํ•ด๋ณผ๊ฒŒ. ๐Ÿ˜Š

์š”์ฆ˜ ์„ธ์ƒ์—์„œ ์†Œํ”„ํŠธ์›จ์–ด๋ฅผ ๋งŒ๋“ ๋‹ค๋Š” ๊ฑด ๋‹จ์ˆœํžˆ ํ•œ ๋‚˜๋ผ, ํ•œ ์–ธ์–ด๋งŒ์„ ์œ„ํ•œ ๊ฒŒ ์•„๋‹ˆ์•ผ. ์ „ ์„ธ๊ณ„ ์‚ฌ๋žŒ๋“ค์ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋งŒ๋“ค์–ด์•ผ ํ•˜๋Š” ์‹œ๋Œ€๊ฐ€ ์™”๊ฑฐ๋“ ! ๐ŸŒ ์˜ˆ๋ฅผ ๋“ค์–ด, ๋„ˆ๊ฐ€ ๋งŒ๋“  ๋ฉ‹์ง„ ์•ฑ์ด ํ•œ๊ตญ์—์„œ๋งŒ ์“ฐ์ด๋Š” ๊ฒŒ ์•„๋‹ˆ๋ผ ๋ฏธ๊ตญ, ์ผ๋ณธ, ์ค‘๊ตญ, ์œ ๋Ÿฝ ๋“ฑ ์ „ ์„ธ๊ณ„์—์„œ ์‚ฌ์šฉ๋œ๋‹ค๋ฉด? ์ •๋ง ๋ฉ‹์ง€์ง€ ์•Š์•„?

๐Ÿ’ก ์žฌ๋ฏธ์žˆ๋Š” ์‚ฌ์‹ค: "i18n"์ด๋ผ๋Š” ์•ฝ์–ด๋Š” internationalization์˜ ์ฒซ ๊ธ€์ž 'i'์™€ ๋งˆ์ง€๋ง‰ ๊ธ€์ž 'n' ์‚ฌ์ด์— 18๊ฐœ์˜ ๊ธ€์ž๊ฐ€ ์žˆ๋‹ค๋Š” ๋œป์ด์•ผ. ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ "l10n"์€ localization์—์„œ 'l'๊ณผ 'n' ์‚ฌ์ด์— 10๊ฐœ์˜ ๊ธ€์ž๊ฐ€ ์žˆ์–ด์„œ ๋ถ™์—ฌ์ง„ ์ด๋ฆ„์ด์ง€!

๊ตญ์ œํ™”(i18n)๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ํŠน์ • ์–ธ์–ด๋‚˜ ์ง€์—ญ์— ์ข…์†๋˜์ง€ ์•Š๋„๋ก ์„ค๊ณ„ํ•˜๋Š” ๊ณผ์ •์ด์•ผ. ์‰ฝ๊ฒŒ ๋งํ•˜๋ฉด, ์ฝ”๋“œ ์•ˆ์— "์•ˆ๋…•ํ•˜์„ธ์š”"๋ผ๊ณ  ํ•˜๋“œ์ฝ”๋”ฉํ•˜๋Š” ๊ฒŒ ์•„๋‹ˆ๋ผ, ๋‚˜์ค‘์— ์–ธ์ œ๋“  ๋‹ค๋ฅธ ์–ธ์–ด๋กœ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ๊ฒŒ ๊ตฌ์กฐ๋ฅผ ๋งŒ๋“œ๋Š” ๊ฑฐ์ง€. ๐Ÿ—๏ธ

์ง€์—ญํ™”(l10n)๋Š” ์‹ค์ œ๋กœ ํŠน์ • ์–ธ์–ด์™€ ๋ฌธํ™”๊ถŒ์— ๋งž๊ฒŒ ์ฝ˜ํ…์ธ ๋ฅผ ๋ฒˆ์—ญํ•˜๊ณ  ์กฐ์ •ํ•˜๋Š” ์ž‘์—…์ด์•ผ. ๋‹จ์ˆœํžˆ ์–ธ์–ด๋งŒ ๋ฐ”๊พธ๋Š” ๊ฒŒ ์•„๋‹ˆ๋ผ ๋‚ ์งœ ํ˜•์‹, ํ†ตํ™” ๋‹จ์œ„, ์ˆซ์ž ํ‘œ๊ธฐ๋ฒ•๊นŒ์ง€ ๊ฐ ๋‚˜๋ผ์˜ ๊ด€์Šต์— ๋งž์ถฐ์•ผ ํ•ด. ๐Ÿ“…๐Ÿ’ฐ

๐ŸŽ“ ์‹ค๋ฌด ํŒ: ์žฌ๋Šฅ๋„ท ๊ฐ™์€ ํ”Œ๋žซํผ์—์„œ ๊ธ€๋กœ๋ฒŒ ์„œ๋น„์Šค๋ฅผ ์ œ๊ณตํ•œ๋‹ค๋ฉด, ์ฒ˜์Œ๋ถ€ํ„ฐ ๊ตญ์ œํ™”๋ฅผ ์—ผ๋‘์— ๋‘๊ณ  ์„ค๊ณ„ํ•˜๋Š” ๊ฒŒ ํ›จ์”ฌ ํšจ์œจ์ ์ด์•ผ. ๋‚˜์ค‘์— ์ถ”๊ฐ€ํ•˜๋ ค๋ฉด ์ฝ”๋“œ๋ฅผ ์ „๋ถ€ ๋œฏ์–ด๊ณ ์ณ์•ผ ํ•˜๊ฑฐ๋“ !

๐Ÿ”ง ResourceBundle์ด ๋ญ๊ธธ๋ž˜?

์ž๋ฐ”์—์„œ ๋‹ค๊ตญ์–ด ์ง€์›์˜ ํ•ต์‹ฌ์€ ๋ฐ”๋กœ ResourceBundle์ด์•ผ! ์ด ์นœ๊ตฌ๋Š” ์ž๋ฐ”๊ฐ€ ๊ธฐ๋ณธ์œผ๋กœ ์ œ๊ณตํ•˜๋Š” ๊ฐ•๋ ฅํ•œ ๋„๊ตฌ๋กœ, ์–ธ์–ด๋ณ„๋กœ ๋‹ค๋ฅธ ํ…์ŠคํŠธ๋ฅผ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค˜. ๐ŸŽ

ResourceBundle์˜ ์ž‘๋™ ์›๋ฆฌ๋Š” ์ƒ๊ฐ๋ณด๋‹ค ๊ฐ„๋‹จํ•ด. ๊ฐ ์–ธ์–ด๋ณ„๋กœ properties ํŒŒ์ผ์„ ๋งŒ๋“ค๊ณ , ๊ทธ ์•ˆ์— ํ‚ค-๊ฐ’ ์Œ์œผ๋กœ ๋ฒˆ์—ญ๋œ ํ…์ŠคํŠธ๋ฅผ ์ €์žฅํ•˜๋Š” ๊ฑฐ์•ผ. ๊ทธ๋Ÿฌ๋ฉด ์ž๋ฐ” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์‚ฌ์šฉ์ž์˜ ๋กœ์ผ€์ผ(Locale)์— ๋”ฐ๋ผ ์ž๋™์œผ๋กœ ์ ์ ˆํ•œ ํŒŒ์ผ์„ ์„ ํƒํ•ด์„œ ํ…์ŠคํŠธ๋ฅผ ๊ฐ€์ ธ์˜ค์ง€! ๐ŸŽฏ

๐Ÿ“ฆ ResourceBundle์˜ ์ฃผ์š” ํŠน์ง•

1๏ธโƒฃ ์ž๋™ ํด๋ฐฑ(Fallback) ๋ฉ”์ปค๋‹ˆ์ฆ˜
๋งŒ์•ฝ ํŠน์ • ์–ธ์–ด์˜ ๋ฆฌ์†Œ์Šค ํŒŒ์ผ์ด ์—†์œผ๋ฉด, ์ž๋™์œผ๋กœ ๊ธฐ๋ณธ ์–ธ์–ด๋กœ ๋Œ์•„๊ฐ€. ์˜ˆ๋ฅผ ๋“ค์–ด messages_fr_CA.properties(์บ๋‚˜๋‹ค ํ”„๋ž‘์Šค์–ด)๊ฐ€ ์—†์œผ๋ฉด messages_fr.properties(ํ”„๋ž‘์Šค์–ด)๋ฅผ ์ฐพ๊ณ , ๊ทธ๊ฒƒ๋„ ์—†์œผ๋ฉด messages.properties(๊ธฐ๋ณธ)๋ฅผ ์‚ฌ์šฉํ•ด.

2๏ธโƒฃ ๊ณ„์ธต์  ๊ตฌ์กฐ
์–ธ์–ด(language), ๊ตญ๊ฐ€(country), ๋ณ€ํ˜•(variant) ์ˆœ์œผ๋กœ ์„ธ๋ฐ€ํ•˜๊ฒŒ ์ง€์—ญํ™”ํ•  ์ˆ˜ ์žˆ์–ด. ๊ฐ™์€ ์˜์–ด๋ผ๋„ ๋ฏธ๊ตญ ์˜์–ด(en_US)์™€ ์˜๊ตญ ์˜์–ด(en_GB)๋ฅผ ๊ตฌ๋ถ„ํ•  ์ˆ˜ ์žˆ์ง€!

3๏ธโƒฃ ์บ์‹ฑ ๊ธฐ๋Šฅ
ํ•œ ๋ฒˆ ๋กœ๋“œ๋œ ResourceBundle์€ ๋ฉ”๋ชจ๋ฆฌ์— ์บ์‹œ๋˜์–ด์„œ ์„ฑ๋Šฅ์ด ์ข‹์•„. ๋งค๋ฒˆ ํŒŒ์ผ์„ ์ฝ์„ ํ•„์š”๊ฐ€ ์—†๊ฑฐ๋“ ! โšก

4๏ธโƒฃ ์œ ๋‹ˆ์ฝ”๋“œ ์ง€์›
properties ํŒŒ์ผ์€ ๊ธฐ๋ณธ์ ์œผ๋กœ ISO-8859-1 ์ธ์ฝ”๋”ฉ์„ ์‚ฌ์šฉํ•˜์ง€๋งŒ, ์œ ๋‹ˆ์ฝ”๋“œ ์ด์Šค์ผ€์ดํ”„ ์‹œํ€€์Šค(\uXXXX)๋ฅผ ํ†ตํ•ด ๋ชจ๋“  ์–ธ์–ด๋ฅผ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ์–ด.

ResourceBundle์—๋Š” ํฌ๊ฒŒ ๋‘ ๊ฐ€์ง€ ํƒ€์ž…์ด ์žˆ์–ด:

PropertyResourceBundle: ๊ฐ€์žฅ ํ”ํ•˜๊ฒŒ ์‚ฌ์šฉ๋˜๋Š” ํƒ€์ž…์œผ๋กœ, .properties ํŒŒ์ผ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•ด. ํ…์ŠคํŠธ ํŒŒ์ผ์ด๋ผ ํŽธ์ง‘ํ•˜๊ธฐ ์‰ฝ๊ณ , ๊ฐœ๋ฐœ์ž๊ฐ€ ์•„๋‹Œ ๋ฒˆ์—ญ๊ฐ€๋„ ์‰ฝ๊ฒŒ ์ž‘์—…ํ•  ์ˆ˜ ์žˆ์–ด. ๐Ÿ“

ListResourceBundle: ์ž๋ฐ” ํด๋ž˜์Šค๋กœ ์ง์ ‘ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐฉ์‹์ด์•ผ. properties ํŒŒ์ผ๋ณด๋‹ค ์œ ์—ฐํ•˜๊ณ , ๋ฌธ์ž์—ด์ด ์•„๋‹Œ ๊ฐ์ฒด๋„ ์ €์žฅํ•  ์ˆ˜ ์žˆ์–ด. ํ•˜์ง€๋งŒ ๋ฒˆ์—ญํ•  ๋•Œ๋งˆ๋‹ค ์ปดํŒŒ์ผํ•ด์•ผ ํ•œ๋‹ค๋Š” ๋‹จ์ ์ด ์žˆ์ง€. ๐Ÿ”จ

๐Ÿš€ ์‹ค์ „! ResourceBundle ์‚ฌ์šฉํ•˜๊ธฐ

์ž, ์ด์ œ ์‹ค์ œ๋กœ ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•˜๋Š”์ง€ ์ฝ”๋“œ๋กœ ์‚ดํŽด๋ณผ๊นŒ? ๋จผ์ € ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ๋ถ€ํ„ฐ ์žก์•„๋ณด์ž! ๐Ÿ—๏ธ

๐Ÿ“ ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ ์˜ˆ์‹œ:
src/
  โ””โ”€โ”€ main/
      โ””โ”€โ”€ resources/
          โ”œโ”€โ”€ messages.properties (๊ธฐ๋ณธ, ์˜์–ด)
          โ”œโ”€โ”€ messages_ko.properties (ํ•œ๊ตญ์–ด)
          โ”œโ”€โ”€ messages_ja.properties (์ผ๋ณธ์–ด)
          โ””โ”€โ”€ messages_zh.properties (์ค‘๊ตญ์–ด)

๐Ÿ“ Step 1: Properties ํŒŒ์ผ ๋งŒ๋“ค๊ธฐ

๋จผ์ € ๊ฐ ์–ธ์–ด๋ณ„๋กœ properties ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด์•ผ ํ•ด. ํŒŒ์ผ ์ด๋ฆ„์€ ๋ฐ˜๋“œ์‹œ basename_์–ธ์–ด์ฝ”๋“œ_๊ตญ๊ฐ€์ฝ”๋“œ.properties ํ˜•์‹์„ ๋”ฐ๋ผ์•ผ ํ•ด!

messages.properties (๊ธฐ๋ณธ ์˜์–ด)
greeting=Hello, {0}!
welcome.message=Welcome to our application
button.submit=Submit
button.cancel=Cancel
error.required=This field is required
error.invalid.email=Please enter a valid email address
menu.home=Home
menu.about=About
menu.contact=Contact
farewell=Goodbye, see you soon!
messages_ko.properties (ํ•œ๊ตญ์–ด)
greeting=์•ˆ๋…•ํ•˜์„ธ์š”, {0}๋‹˜!
welcome.message=์šฐ๋ฆฌ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ์˜ค์‹  ๊ฒƒ์„ ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค
button.submit=์ œ์ถœ
button.cancel=์ทจ์†Œ
error.required=์ด ํ•ญ๋ชฉ์€ ํ•„์ˆ˜์ž…๋‹ˆ๋‹ค
error.invalid.email=์˜ฌ๋ฐ”๋ฅธ ์ด๋ฉ”์ผ ์ฃผ์†Œ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”
menu.home=ํ™ˆ
menu.about=์†Œ๊ฐœ
menu.contact=์—ฐ๋ฝ์ฒ˜
farewell=์•ˆ๋…•ํžˆ ๊ฐ€์„ธ์š”, ๋˜ ๋งŒ๋‚˜์š”!
messages_ja.properties (์ผ๋ณธ์–ด)
greeting=ใ“ใ‚“ใซใกใฏใ€{0}ใ•ใ‚“๏ผ
welcome.message=็งใŸใกใฎใ‚ขใƒ—ใƒชใ‚ฑใƒผใ‚ทใƒงใƒณใธใ‚ˆใ†ใ“ใ
button.submit=้€ไฟก
button.cancel=ใ‚ญใƒฃใƒณใ‚ปใƒซ
error.required=ใ“ใฎ้ …็›ฎใฏๅฟ…้ ˆใงใ™
error.invalid.email=ๆœ‰ๅŠนใชใƒกใƒผใƒซใ‚ขใƒ‰ใƒฌใ‚นใ‚’ๅ…ฅๅŠ›ใ—ใฆใใ ใ•ใ„
menu.home=ใƒ›ใƒผใƒ 
menu.about=ใซใคใ„ใฆ
menu.contact=ใŠๅ•ใ„ๅˆใ‚ใ›
farewell=ใ•ใ‚ˆใ†ใชใ‚‰ใ€ใพใŸใŠไผšใ„ใ—ใพใ—ใ‚‡ใ†๏ผ
โš ๏ธ ์ฃผ์˜์‚ฌํ•ญ: properties ํŒŒ์ผ์— ํ•œ๊ธ€์ด๋‚˜ ์ผ๋ณธ์–ด ๊ฐ™์€ ๋น„ASCII ๋ฌธ์ž๋ฅผ ์ง์ ‘ ์ž…๋ ฅํ•˜๋ฉด ์ธ์ฝ”๋”ฉ ๋ฌธ์ œ๊ฐ€ ์ƒ๊ธธ ์ˆ˜ ์žˆ์–ด. Java 9 ์ด์ „ ๋ฒ„์ „์—์„œ๋Š” ๋ฐ˜๋“œ์‹œ native2ascii ๋„๊ตฌ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์œ ๋‹ˆ์ฝ”๋“œ ์ด์Šค์ผ€์ดํ”„ ์‹œํ€€์Šค๋กœ ๋ณ€ํ™˜ํ•ด์•ผ ํ•ด. Java 9๋ถ€ํ„ฐ๋Š” UTF-8์„ ๊ธฐ๋ณธ์œผ๋กœ ์ง€์›ํ•˜๋‹ˆ๊นŒ ๊ฑฑ์ • ์—†์–ด! ๐ŸŽ‰

๐Ÿ’ป Step 2: ์ž๋ฐ” ์ฝ”๋“œ์—์„œ ์‚ฌ์šฉํ•˜๊ธฐ

์ด์ œ ์ž๋ฐ” ์ฝ”๋“œ์—์„œ ResourceBundle์„ ๋กœ๋“œํ•˜๊ณ  ์‚ฌ์šฉํ•ด๋ณด์ž!

import java.util.Locale;
import java.util.ResourceBundle;

public class InternationalizationDemo {
    
    public static void main(String[] args) {
        // ํ•œ๊ตญ์–ด ๋กœ์ผ€์ผ๋กœ ResourceBundle ๋กœ๋“œ
        Locale koreanLocale = new Locale("ko", "KR");
        ResourceBundle koreanBundle = ResourceBundle.getBundle("messages", koreanLocale);
        
        // ์˜์–ด ๋กœ์ผ€์ผ๋กœ ResourceBundle ๋กœ๋“œ
        Locale englishLocale = new Locale("en", "US");
        ResourceBundle englishBundle = ResourceBundle.getBundle("messages", englishLocale);
        
        // ์ผ๋ณธ์–ด ๋กœ์ผ€์ผ๋กœ ResourceBundle ๋กœ๋“œ
        Locale japaneseLocale = new Locale("ja", "JP");
        ResourceBundle japaneseBundle = ResourceBundle.getBundle("messages", japaneseLocale);
        
        // ํ•œ๊ตญ์–ด ์ถœ๋ ฅ
        System.out.println("=== ํ•œ๊ตญ์–ด ===");
        System.out.println(koreanBundle.getString("welcome.message"));
        System.out.println(koreanBundle.getString("button.submit"));
        
        // ์˜์–ด ์ถœ๋ ฅ
        System.out.println("\n=== English ===");
        System.out.println(englishBundle.getString("welcome.message"));
        System.out.println(englishBundle.getString("button.submit"));
        
        // ์ผ๋ณธ์–ด ์ถœ๋ ฅ
        System.out.println("\n=== ๆ—ฅๆœฌ่ชž ===");
        System.out.println(japaneseBundle.getString("welcome.message"));
        System.out.println(japaneseBundle.getString("button.submit"));
    }
}

์œ„ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ๊ฐ ์–ธ์–ด๋กœ ๋ฉ”์‹œ์ง€๊ฐ€ ์ถœ๋ ฅ๋˜๋Š” ๊ฑธ ๋ณผ ์ˆ˜ ์žˆ์–ด! ์‹ ๊ธฐํ•˜์ง€? ๐Ÿ˜„

๐ŸŽจ Step 3: ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ์žˆ๋Š” ๋ฉ”์‹œ์ง€ ์ฒ˜๋ฆฌํ•˜๊ธฐ

์‹ค์ œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ๋Š” ๋™์ ์ธ ๊ฐ’์„ ๋ฉ”์‹œ์ง€์— ํฌํ•จํ•ด์•ผ ํ•  ๋•Œ๊ฐ€ ๋งŽ์•„. ์˜ˆ๋ฅผ ๋“ค์–ด "์•ˆ๋…•ํ•˜์„ธ์š”, ํ™๊ธธ๋™๋‹˜!"์ฒ˜๋Ÿผ ์‚ฌ์šฉ์ž ์ด๋ฆ„์„ ๋„ฃ์–ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ ๋ง์ด์•ผ. ์ด๋Ÿด ๋•Œ๋Š” MessageFormat ํด๋ž˜์Šค๋ฅผ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๋ฉด ๋ผ!

import java.text.MessageFormat;
import java.util.Locale;
import java.util.ResourceBundle;

public class MessageFormatDemo {
    
    public static void main(String[] args) {
        // ํ•œ๊ตญ์–ด ๋กœ์ผ€์ผ
        Locale koreanLocale = new Locale("ko", "KR");
        ResourceBundle bundle = ResourceBundle.getBundle("messages", koreanLocale);
        
        // ์‚ฌ์šฉ์ž ์ด๋ฆ„์„ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ „๋‹ฌ
        String userName = "ํ™๊ธธ๋™";
        String greetingPattern = bundle.getString("greeting");
        String greeting = MessageFormat.format(greetingPattern, userName);
        
        System.out.println(greeting); // ์ถœ๋ ฅ: ์•ˆ๋…•ํ•˜์„ธ์š”, ํ™๊ธธ๋™๋‹˜!
        
        // ์˜์–ด ๋กœ์ผ€์ผ๋กœ ๋ณ€๊ฒฝ
        Locale englishLocale = new Locale("en", "US");
        bundle = ResourceBundle.getBundle("messages", englishLocale);
        
        userName = "John";
        greetingPattern = bundle.getString("greeting");
        greeting = MessageFormat.format(greetingPattern, userName);
        
        System.out.println(greeting); // ์ถœ๋ ฅ: Hello, John!
    }
}

MessageFormat์€ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๋งค๊ฐœ๋ณ€์ˆ˜๋„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ์–ด. properties ํŒŒ์ผ์— {0}, {1}, {2} ๊ฐ™์€ ํ”Œ๋ ˆ์ด์Šคํ™€๋”๋ฅผ ๋„ฃ๊ณ , ์ˆœ์„œ๋Œ€๋กœ ๊ฐ’์„ ์ „๋‹ฌํ•˜๋ฉด ๋ผ! ๐Ÿ“Š

์˜ˆ์‹œ:
order.confirmation=์ฃผ๋ฌธ์ด ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ฃผ๋ฌธ๋ฒˆํ˜ธ: {0}, ๊ธˆ์•ก: {1}์›, ๋ฐฐ์†ก์˜ˆ์ •์ผ: {2}
๊ทธ๋ฆฌ๊ณ  ์ž๋ฐ” ์ฝ”๋“œ์—์„œ:
String message = MessageFormat.format(
    bundle.getString("order.confirmation"),
    "ORD-12345",
    "50000",
    "2024-01-15"
);

๐ŸŒ Locale ํด๋ž˜์Šค ์™„์ „ ์ •๋ณต

ResourceBundle๊ณผ ํ•จ๊ป˜ ๋ฐ˜๋“œ์‹œ ์•Œ์•„์•ผ ํ•  ๊ฒŒ ๋ฐ”๋กœ Locale ํด๋ž˜์Šค์•ผ. Locale์€ ํŠน์ • ์ง€์—ญ์ด๋‚˜ ์–ธ์–ด๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ๊ฐ์ฒด๋กœ, ๊ตญ์ œํ™”์˜ ํ•ต์‹ฌ ๊ฐœ๋…์ด์ง€! ๐Ÿ—บ๏ธ

๐ŸŽฏ Locale ์ƒ์„ฑ ๋ฐฉ๋ฒ•

Locale ๊ฐ์ฒด๋ฅผ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์€ ์—ฌ๋Ÿฌ ๊ฐ€์ง€๊ฐ€ ์žˆ์–ด:

// ๋ฐฉ๋ฒ• 1: ์ƒ์„ฑ์ž ์‚ฌ์šฉ
Locale locale1 = new Locale("ko"); // ์–ธ์–ด๋งŒ
Locale locale2 = new Locale("ko", "KR"); // ์–ธ์–ด + ๊ตญ๊ฐ€
Locale locale3 = new Locale("ko", "KR", "seoul"); // ์–ธ์–ด + ๊ตญ๊ฐ€ + ๋ณ€ํ˜•

// ๋ฐฉ๋ฒ• 2: ์ƒ์ˆ˜ ์‚ฌ์šฉ (์ž์ฃผ ์“ฐ์ด๋Š” ๋กœ์ผ€์ผ)
Locale locale4 = Locale.KOREA;
Locale locale5 = Locale.US;
Locale locale6 = Locale.JAPAN;
Locale locale7 = Locale.CHINA;

// ๋ฐฉ๋ฒ• 3: Locale.Builder ์‚ฌ์šฉ (Java 7+, ๊ถŒ์žฅ)
Locale locale8 = new Locale.Builder()
    .setLanguage("ko")
    .setRegion("KR")
    .setVariant("seoul")
    .build();

// ๋ฐฉ๋ฒ• 4: forLanguageTag ์‚ฌ์šฉ (BCP 47 ํ‘œ์ค€)
Locale locale9 = Locale.forLanguageTag("ko-KR");
Locale locale10 = Locale.forLanguageTag("en-US");

// ์‹œ์Šคํ…œ ๊ธฐ๋ณธ ๋กœ์ผ€์ผ ๊ฐ€์ ธ์˜ค๊ธฐ
Locale defaultLocale = Locale.getDefault();
System.out.println("์‹œ์Šคํ…œ ๊ธฐ๋ณธ ๋กœ์ผ€์ผ: " + defaultLocale);

// ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ๋กœ์ผ€์ผ ํ™•์ธ
Locale[] availableLocales = Locale.getAvailableLocales();
System.out.println("์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋กœ์ผ€์ผ ์ˆ˜: " + availableLocales.length);
๐ŸŽ“ Best Practice: Java 7 ์ด์ƒ์„ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด Locale.Builder๋‚˜ forLanguageTag ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒŒ ์ข‹์•„. ๋” ๋ช…ํ™•ํ•˜๊ณ  ํ‘œ์ค€์„ ๋”ฐ๋ฅด๊ฑฐ๋“ !

๐Ÿ“Š Locale ์ •๋ณด ํ™œ์šฉํ•˜๊ธฐ

Locale ๊ฐ์ฒด์—์„œ ๋‹ค์–‘ํ•œ ์ •๋ณด๋ฅผ ์ถ”์ถœํ•  ์ˆ˜ ์žˆ์–ด:

public class LocaleInfoDemo {
    
    public static void main(String[] args) {
        Locale locale = new Locale("ko", "KR");
        
        // ๊ธฐ๋ณธ ์ •๋ณด
        System.out.println("์–ธ์–ด ์ฝ”๋“œ: " + locale.getLanguage()); // ko
        System.out.println("๊ตญ๊ฐ€ ์ฝ”๋“œ: " + locale.getCountry()); // KR
        System.out.println("๋ณ€ํ˜•: " + locale.getVariant()); // (๋น„์–ด์žˆ์Œ)
        
        // ํ‘œ์‹œ ์ด๋ฆ„ (ํ˜„์žฌ ๋กœ์ผ€์ผ ๊ธฐ์ค€)
        System.out.println("์–ธ์–ด ์ด๋ฆ„: " + locale.getDisplayLanguage()); // ํ•œ๊ตญ์–ด
        System.out.println("๊ตญ๊ฐ€ ์ด๋ฆ„: " + locale.getDisplayCountry()); // ๋Œ€ํ•œ๋ฏผ๊ตญ
        System.out.println("์ „์ฒด ์ด๋ฆ„: " + locale.getDisplayName()); // ํ•œ๊ตญ์–ด (๋Œ€ํ•œ๋ฏผ๊ตญ)
        
        // ๋‹ค๋ฅธ ๋กœ์ผ€์ผ ๊ธฐ์ค€์œผ๋กœ ํ‘œ์‹œ
        System.out.println("\n์˜์–ด๋กœ ํ‘œ์‹œ:");
        System.out.println("์–ธ์–ด: " + locale.getDisplayLanguage(Locale.ENGLISH)); // Korean
        System.out.println("๊ตญ๊ฐ€: " + locale.getDisplayCountry(Locale.ENGLISH)); // South Korea
        
        // ISO ์ฝ”๋“œ
        System.out.println("\nISO ์ฝ”๋“œ:");
        System.out.println("ISO3 ์–ธ์–ด: " + locale.getISO3Language()); // kor
        System.out.println("ISO3 ๊ตญ๊ฐ€: " + locale.getISO3Country()); // KOR
    }
}

๐ŸŽจ ๊ณ ๊ธ‰ ๊ธฐ๋Šฅ: ListResourceBundle ํ™œ์šฉํ•˜๊ธฐ

์•ž์—์„œ properties ํŒŒ์ผ์„ ์‚ฌ์šฉํ•˜๋Š” PropertyResourceBundle์„ ๋ดค๋Š”๋ฐ, ์ด๋ฒˆ์—” ์ž๋ฐ” ํด๋ž˜์Šค๋กœ ์ง์ ‘ ๊ตฌํ˜„ํ•˜๋Š” ListResourceBundle์„ ์•Œ์•„๋ณผ๊ฒŒ! ๐Ÿ’Ž

ListResourceBundle์€ properties ํŒŒ์ผ๋ณด๋‹ค ๋” ๋ณต์žกํ•œ ๊ฐ์ฒด๋ฅผ ์ €์žฅํ•  ์ˆ˜ ์žˆ์–ด. ๋ฌธ์ž์—ด๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๋ฐฐ์—ด, ๋ฆฌ์ŠคํŠธ, ์‹ฌ์ง€์–ด ์ปค์Šคํ…€ ๊ฐ์ฒด๋„ ๊ฐ€๋Šฅํ•˜์ง€! ๐Ÿš€

๐Ÿ“ ListResourceBundle ๊ตฌํ˜„ ์˜ˆ์‹œ

import java.util.ListResourceBundle;

// ์˜์–ด ๋ฆฌ์†Œ์Šค
public class MyResources extends ListResourceBundle {
    
    @Override
    protected Object[][] getContents() {
        return new Object[][] {
            // ๋ฌธ์ž์—ด
            {"greeting", "Hello!"},
            {"farewell", "Goodbye!"},
            
            // ๋ฐฐ์—ด
            {"weekdays", new String[] {
                "Monday", "Tuesday", "Wednesday", 
                "Thursday", "Friday", "Saturday", "Sunday"
            }},
            
            // ์ˆซ์ž
            {"maxUsers", 1000},
            
            // ๋ณต์žกํ•œ ๊ฐ์ฒด
            {"colors", new String[] {"Red", "Green", "Blue"}},
            
            // ์ค‘์ฒฉ ๋ฐฐ์—ด
            {"matrix", new int[][] {
                {1, 2, 3},
                {4, 5, 6},
                {7, 8, 9}
            }}
        };
    }
}
import java.util.ListResourceBundle;

// ํ•œ๊ตญ์–ด ๋ฆฌ์†Œ์Šค
public class MyResources_ko extends ListResourceBundle {
    
    @Override
    protected Object[][] getContents() {
        return new Object[][] {
            {"greeting", "์•ˆ๋…•ํ•˜์„ธ์š”!"},
            {"farewell", "์•ˆ๋…•ํžˆ ๊ฐ€์„ธ์š”!"},
            
            {"weekdays", new String[] {
                "์›”์š”์ผ", "ํ™”์š”์ผ", "์ˆ˜์š”์ผ", 
                "๋ชฉ์š”์ผ", "๊ธˆ์š”์ผ", "ํ† ์š”์ผ", "์ผ์š”์ผ"
            }},
            
            {"maxUsers", 1000},
            
            {"colors", new String[] {"๋นจ๊ฐ•", "์ดˆ๋ก", "ํŒŒ๋ž‘"}},
            
            {"matrix", new int[][] {
                {1, 2, 3},
                {4, 5, 6},
                {7, 8, 9}
            }}
        };
    }
}

๐Ÿ’ป ListResourceBundle ์‚ฌ์šฉํ•˜๊ธฐ

import java.util.Locale;
import java.util.ResourceBundle;

public class ListResourceBundleDemo {
    
    public static void main(String[] args) {
        // ํ•œ๊ตญ์–ด ๋กœ์ผ€์ผ
        Locale locale = new Locale("ko");
        ResourceBundle bundle = ResourceBundle.getBundle("MyResources", locale);
        
        // ๋ฌธ์ž์—ด ๊ฐ€์ ธ์˜ค๊ธฐ
        System.out.println(bundle.getString("greeting"));
        
        // ๋ฐฐ์—ด ๊ฐ€์ ธ์˜ค๊ธฐ
        String[] weekdays = (String[]) bundle.getObject("weekdays");
        System.out.println("์š”์ผ๋“ค:");
        for (String day : weekdays) {
            System.out.println("  - " + day);
        }
        
        // ์ˆซ์ž ๊ฐ€์ ธ์˜ค๊ธฐ
        int maxUsers = (Integer) bundle.getObject("maxUsers");
        System.out.println("์ตœ๋Œ€ ์‚ฌ์šฉ์ž ์ˆ˜: " + maxUsers);
        
        // 2์ฐจ์› ๋ฐฐ์—ด ๊ฐ€์ ธ์˜ค๊ธฐ
        int[][] matrix = (int[][]) bundle.getObject("matrix");
        System.out.println("ํ–‰๋ ฌ:");
        for (int[] row : matrix) {
            for (int value : row) {
                System.out.print(value + " ");
            }
            System.out.println();
        }
    }
}
๐Ÿค” PropertyResourceBundle vs ListResourceBundle PropertyResourceBundle ์žฅ์ :
  • ํ…์ŠคํŠธ ํŒŒ์ผ์ด๋ผ ํŽธ์ง‘์ด ์‰ฌ์›€
  • ์ปดํŒŒ์ผ ์—†์ด ์ˆ˜์ • ๊ฐ€๋Šฅ
  • ๋ฒˆ์—ญ๊ฐ€๊ฐ€ ์ง์ ‘ ์ž‘์—…ํ•˜๊ธฐ ์ข‹์Œ
  • ๋ฒ„์ „ ๊ด€๋ฆฌ๊ฐ€ ํŽธํ•จ
ListResourceBundle ์žฅ์ :
  • ๋ฌธ์ž์—ด ์™ธ์˜ ๊ฐ์ฒด ์ €์žฅ ๊ฐ€๋Šฅ
  • ํƒ€์ž… ์•ˆ์ •์„ฑ ํ™•๋ณด
  • ๋ณต์žกํ•œ ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ ์ง€์›
  • ์„ฑ๋Šฅ์ด ์•ฝ๊ฐ„ ๋” ์ข‹์Œ (ํŒŒ์‹ฑ ๋ถˆํ•„์š”)

๐Ÿ” ResourceBundle ํด๋ฐฑ ๋ฉ”์ปค๋‹ˆ์ฆ˜ ์ดํ•ดํ•˜๊ธฐ

ResourceBundle์˜ ๊ฐ€์žฅ ๊ฐ•๋ ฅํ•œ ๊ธฐ๋Šฅ ์ค‘ ํ•˜๋‚˜๊ฐ€ ๋ฐ”๋กœ ํด๋ฐฑ(Fallback) ๋ฉ”์ปค๋‹ˆ์ฆ˜์ด์•ผ! ์ด๊ฒŒ ์–ด๋–ป๊ฒŒ ์ž‘๋™ํ•˜๋Š”์ง€ ์ž์„ธํžˆ ์•Œ์•„๋ณด์ž. ๐ŸŽฏ

์˜ˆ๋ฅผ ๋“ค์–ด, ์บ๋‚˜๋‹ค ํ”„๋ž‘์Šค์–ด(fr_CA) ๋กœ์ผ€์ผ๋กœ "messages" ๋ฒˆ๋“ค์„ ์š”์ฒญํ–ˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•ด๋ณด์ž. ResourceBundle์€ ๋‹ค์Œ ์ˆœ์„œ๋กœ ํŒŒ์ผ์„ ์ฐพ์•„:

๐Ÿ”„ ๊ฒ€์ƒ‰ ์ˆœ์„œ

1๋‹จ๊ณ„: messages_fr_CA.properties (๊ฐ€์žฅ ๊ตฌ์ฒด์ )
2๋‹จ๊ณ„: messages_fr.properties (์–ธ์–ด๋งŒ)
3๋‹จ๊ณ„: messages.properties (๊ธฐ๋ณธ)
4๋‹จ๊ณ„: ์ฐพ์ง€ ๋ชปํ•˜๋ฉด MissingResourceException ๋ฐœ์ƒ!

์ด ๊ณผ์ •์—์„œ ListResourceBundle์ด PropertyResourceBundle๋ณด๋‹ค ์šฐ์„ ์ˆœ์œ„๊ฐ€ ๋†’์•„. ์ฆ‰, messages_fr_CA.class๊ฐ€ ์žˆ์œผ๋ฉด messages_fr_CA.properties๋ณด๋‹ค ๋จผ์ € ์‚ฌ์šฉ๋ผ!

import java.util.Locale;
import java.util.ResourceBundle;
import java.util.MissingResourceException;

public class FallbackDemo {
    
    public static void main(String[] args) {
        // ์กด์žฌํ•˜์ง€ ์•Š๋Š” ๋กœ์ผ€์ผ ์‹œ๋„
        Locale locale = new Locale("fr", "CA"); // ์บ๋‚˜๋‹ค ํ”„๋ž‘์Šค์–ด
        
        try {
            ResourceBundle bundle = ResourceBundle.getBundle("messages", locale);
            
            // ์‹ค์ œ๋กœ ๋กœ๋“œ๋œ ๋กœ์ผ€์ผ ํ™•์ธ
            System.out.println("์š”์ฒญํ•œ ๋กœ์ผ€์ผ: " + locale);
            System.out.println("์‹ค์ œ ๋กœ๋“œ๋œ ๋กœ์ผ€์ผ: " + bundle.getLocale());
            
            // messages_fr_CA๊ฐ€ ์—†์œผ๋ฉด messages_fr์„ ์ฐพ๊ณ 
            // ๊ทธ๊ฒƒ๋„ ์—†์œผ๋ฉด messages๋ฅผ ์‚ฌ์šฉํ•จ
            System.out.println(bundle.getString("greeting"));
            
        } catch (MissingResourceException e) {
            System.err.println("๋ฆฌ์†Œ์Šค๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค: " + e.getMessage());
        }
    }
}

๐ŸŽจ ์ปค์Šคํ…€ ํด๋ฐฑ ๋กœ์ง ๊ตฌํ˜„ํ•˜๊ธฐ

๋•Œ๋กœ๋Š” ๊ธฐ๋ณธ ํด๋ฐฑ ๋ฉ”์ปค๋‹ˆ์ฆ˜์œผ๋กœ๋Š” ๋ถ€์กฑํ•  ์ˆ˜ ์žˆ์–ด. ์ด๋Ÿด ๋•Œ๋Š” ResourceBundle.Control์„ ์‚ฌ์šฉํ•ด์„œ ์ปค์Šคํ…€ ๋กœ์ง์„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์–ด! ๐Ÿ› ๏ธ

import java.util.*;
import java.io.IOException;

public class CustomControl extends ResourceBundle.Control {
    
    @Override
    public List<Locale> getCandidateLocales(String baseName, Locale locale) {
        // ์ปค์Šคํ…€ ํด๋ฐฑ ์ˆœ์„œ ์ •์˜
        List<Locale> locales = new ArrayList<>();
        
        if (locale.equals(new Locale("ko", "KR"))) {
            locales.add(locale); // ko_KR
            locales.add(new Locale("ko")); // ko
            locales.add(new Locale("en")); // ์˜์–ด๋กœ ํด๋ฐฑ
            locales.add(Locale.ROOT); // ๊ธฐ๋ณธ
        } else {
            // ๊ธฐ๋ณธ ๋™์ž‘ ์‚ฌ์šฉ
            locales = super.getCandidateLocales(baseName, locale);
        }
        
        return locales;
    }
    
    @Override
    public long getTimeToLive(String baseName, Locale locale) {
        // ์บ์‹œ ์œ ์ง€ ์‹œ๊ฐ„ ์„ค์ • (๋ฐ€๋ฆฌ์ดˆ)
        // TTL_DONT_CACHE: ์บ์‹œ ์•ˆ ํ•จ
        // TTL_NO_EXPIRATION_CONTROL: ๋งŒ๋ฃŒ ์—†์Œ
        return 1000 * 60 * 60; // 1์‹œ๊ฐ„
    }
    
    @Override
    public boolean needsReload(String baseName, Locale locale,
                               String format, ClassLoader loader,
                               ResourceBundle bundle, long loadTime) {
        // ๋ฆฌ์†Œ์Šค ํŒŒ์ผ์ด ๋ณ€๊ฒฝ๋˜์—ˆ๋Š”์ง€ ํ™•์ธ
        return true; // ํ•ญ์ƒ ๋ฆฌ๋กœ๋“œ (๊ฐœ๋ฐœ ์ค‘์— ์œ ์šฉ)
    }
}

// ์‚ฌ์šฉ ์˜ˆ์‹œ
public class CustomControlDemo {
    public static void main(String[] args) {
        Locale locale = new Locale("ko", "KR");
        ResourceBundle.Control control = new CustomControl();
        
        ResourceBundle bundle = ResourceBundle.getBundle(
            "messages", 
            locale, 
            control
        );
        
        System.out.println(bundle.getString("greeting"));
    }
}

๐Ÿ“… ๋‚ ์งœ, ์‹œ๊ฐ„, ์ˆซ์ž ํฌ๋งทํŒ…

๋‹ค๊ตญ์–ด ์ง€์›์€ ๋‹จ์ˆœํžˆ ํ…์ŠคํŠธ ๋ฒˆ์—ญ๋งŒ์ด ์•„๋‹ˆ์•ผ! ๋‚ ์งœ, ์‹œ๊ฐ„, ์ˆซ์ž, ํ†ตํ™” ๋“ฑ๋„ ๊ฐ ๋‚˜๋ผ์˜ ๊ด€์Šต์— ๋งž๊ฒŒ ํ‘œ์‹œํ•ด์•ผ ํ•ด. ์ž๋ฐ”๋Š” ์ด๋ฅผ ์œ„ํ•œ ๊ฐ•๋ ฅํ•œ ๋„๊ตฌ๋“ค์„ ์ œ๊ณตํ•˜์ง€! ๐Ÿ“Š

๐Ÿ“… ๋‚ ์งœ์™€ ์‹œ๊ฐ„ ํฌ๋งทํŒ…

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class DateFormattingDemo {
    
    public static void main(String[] args) {
        Date now = new Date();
        
        // ํ•œ๊ตญ์–ด ๋กœ์ผ€์ผ
        Locale koreaLocale = new Locale("ko", "KR");
        DateFormat koreanDateFormat = DateFormat.getDateInstance(
            DateFormat.LONG, 
            koreaLocale
        );
        DateFormat koreanTimeFormat = DateFormat.getTimeInstance(
            DateFormat.LONG, 
            koreaLocale
        );
        DateFormat koreanDateTimeFormat = DateFormat.getDateTimeInstance(
            DateFormat.LONG, 
            DateFormat.LONG, 
            koreaLocale
        );
        
        System.out.println("=== ํ•œ๊ตญ์–ด ===");
        System.out.println("๋‚ ์งœ: " + koreanDateFormat.format(now));
        System.out.println("์‹œ๊ฐ„: " + koreanTimeFormat.format(now));
        System.out.println("๋‚ ์งœ+์‹œ๊ฐ„: " + koreanDateTimeFormat.format(now));
        
        // ๋ฏธ๊ตญ ์˜์–ด ๋กœ์ผ€์ผ
        Locale usLocale = Locale.US;
        DateFormat usDateFormat = DateFormat.getDateInstance(
            DateFormat.LONG, 
            usLocale
        );
        DateFormat usTimeFormat = DateFormat.getTimeInstance(
            DateFormat.LONG, 
            usLocale
        );
        
        System.out.println("\n=== English (US) ===");
        System.out.println("Date: " + usDateFormat.format(now));
        System.out.println("Time: " + usTimeFormat.format(now));
        
        // ์ผ๋ณธ์–ด ๋กœ์ผ€์ผ
        Locale japanLocale = Locale.JAPAN;
        DateFormat japanDateFormat = DateFormat.getDateInstance(
            DateFormat.LONG, 
            japanLocale
        );
        
        System.out.println("\n=== ๆ—ฅๆœฌ่ชž ===");
        System.out.println("ๆ—ฅไป˜: " + japanDateFormat.format(now));
        
        // ์ปค์Šคํ…€ ํŒจํ„ด ์‚ฌ์šฉ
        SimpleDateFormat customFormat = new SimpleDateFormat(
            "yyyy๋…„ MM์›” dd์ผ E์š”์ผ", 
            koreaLocale
        );
        System.out.println("\n์ปค์Šคํ…€ ํฌ๋งท: " + customFormat.format(now));
    }
}
๐Ÿ’ก Java 8+ ์‚ฌ์šฉ์ž๋ผ๋ฉด: ์ƒˆ๋กœ์šด java.time ํŒจํ‚ค์ง€์˜ DateTimeFormatter๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒŒ ๋” ์ข‹์•„! ๋” ์ง๊ด€์ ์ด๊ณ  ๋ถˆ๋ณ€ ๊ฐ์ฒด๋ผ ์Šค๋ ˆ๋“œ ์•ˆ์ „ํ•ด.
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.Locale;

public class ModernDateFormattingDemo {
    
    public static void main(String[] args) {
        LocalDateTime now = LocalDateTime.now();
        
        // ํ•œ๊ตญ์–ด
        DateTimeFormatter koreanFormatter = DateTimeFormatter
            .ofLocalizedDateTime(FormatStyle.LONG)
            .withLocale(new Locale("ko", "KR"));
        System.out.println("ํ•œ๊ตญ์–ด: " + now.format(koreanFormatter));
        
        // ์˜์–ด
        DateTimeFormatter englishFormatter = DateTimeFormatter
            .ofLocalizedDateTime(FormatStyle.LONG)
            .withLocale(Locale.US);
        System.out.println("English: " + now.format(englishFormatter));
        
        // ์ปค์Šคํ…€ ํŒจํ„ด
        DateTimeFormatter customFormatter = DateTimeFormatter
            .ofPattern("yyyy๋…„ M์›” d์ผ (E) a h:mm", new Locale("ko", "KR"));
        System.out.println("์ปค์Šคํ…€: " + now.format(customFormatter));
    }
}

๐Ÿ’ฐ ์ˆซ์ž์™€ ํ†ตํ™” ํฌ๋งทํŒ…

์ˆซ์ž ํ‘œ๊ธฐ๋ฒ•๋„ ๋‚˜๋ผ๋งˆ๋‹ค ๋‹ฌ๋ผ. ํ•œ๊ตญ์€ 1,000,000์›์ด์ง€๋งŒ ๋ฏธ๊ตญ์€ $1,000,000.00์ด๊ณ , ์œ ๋Ÿฝ ์ผ๋ถ€ ๊ตญ๊ฐ€๋Š” 1.000.000,00โ‚ฌ ์ด๋Ÿฐ ์‹์ด์•ผ! ๐ŸŒ

import java.text.NumberFormat;
import java.util.Locale;

public class NumberFormattingDemo {
    
    public static void main(String[] args) {
        double number = 1234567.89;
        double currency = 1234567.89;
        double percent = 0.75;
        
        // ํ•œ๊ตญ
        Locale koreaLocale = new Locale("ko", "KR");
        NumberFormat koreanNumberFormat = NumberFormat.getNumberInstance(koreaLocale);
        NumberFormat koreanCurrencyFormat = NumberFormat.getCurrencyInstance(koreaLocale);
        NumberFormat koreanPercentFormat = NumberFormat.getPercentInstance(koreaLocale);
        
        System.out.println("=== ํ•œ๊ตญ ===");
        System.out.println("์ˆซ์ž: " + koreanNumberFormat.format(number));
        System.out.println("ํ†ตํ™”: " + koreanCurrencyFormat.format(currency));
        System.out.println("ํผ์„ผํŠธ: " + koreanPercentFormat.format(percent));
        
        // ๋ฏธ๊ตญ
        Locale usLocale = Locale.US;
        NumberFormat usNumberFormat = NumberFormat.getNumberInstance(usLocale);
        NumberFormat usCurrencyFormat = NumberFormat.getCurrencyInstance(usLocale);
        NumberFormat usPercentFormat = NumberFormat.getPercentInstance(usLocale);
        
        System.out.println("\n=== USA ===");
        System.out.println("Number: " + usNumberFormat.format(number));
        System.out.println("Currency: " + usCurrencyFormat.format(currency));
        System.out.println("Percent: " + usPercentFormat.format(percent));
        
        // ๋…์ผ
        Locale germanyLocale = Locale.GERMANY;
        NumberFormat germanNumberFormat = NumberFormat.getNumberInstance(germanyLocale);
        NumberFormat germanCurrencyFormat = NumberFormat.getCurrencyInstance(germanyLocale);
        
        System.out.println("\n=== Deutschland ===");
        System.out.println("Nummer: " + germanNumberFormat.format(number));
        System.out.println("Wรคhrung: " + germanCurrencyFormat.format(currency));
        
        // ์†Œ์ˆ˜์  ์ž๋ฆฟ์ˆ˜ ์กฐ์ •
        NumberFormat customFormat = NumberFormat.getNumberInstance(koreaLocale);
        customFormat.setMinimumFractionDigits(2);
        customFormat.setMaximumFractionDigits(4);
        System.out.println("\n์ปค์Šคํ…€ ํฌ๋งท: " + customFormat.format(number));
    }
}

๐ŸŽฏ ์‹ค์ „ ํ”„๋กœ์ ํŠธ: ๋‹ค๊ตญ์–ด ์ง€์› ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜

์ด์ œ ๋ฐฐ์šด ๋‚ด์šฉ์„ ์ข…ํ•ฉํ•ด์„œ ์‹ค์ œ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•˜๋Š”์ง€ ์•Œ์•„๋ณด์ž! ๐Ÿš€ Spring Framework๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์˜ˆ์‹œ๋ฅผ ๋ณด์—ฌ์ค„๊ฒŒ.

๐ŸŒธ Spring Boot์—์„œ ๊ตญ์ œํ™” ์„ค์ •ํ•˜๊ธฐ

application.properties
# ๊ธฐ๋ณธ ๋กœ์ผ€์ผ ์„ค์ •
spring.web.locale=ko_KR
# ๋กœ์ผ€์ผ ๋ณ€๊ฒฝ ํŒŒ๋ผ๋ฏธํ„ฐ ์ด๋ฆ„
spring.web.locale-resolver=fixed
# ๋ฉ”์‹œ์ง€ ์†Œ์Šค ๋ฒ ์ด์Šค๋„ค์ž„
spring.messages.basename=messages
# ์ธ์ฝ”๋”ฉ
spring.messages.encoding=UTF-8
# ์บ์‹œ ์‹œ๊ฐ„ (์ดˆ, -1์€ ์˜๊ตฌ)
spring.messages.cache-duration=3600
LocaleConfiguration.java
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;

import java.util.Locale;

@Configuration
public class LocaleConfiguration implements WebMvcConfigurer {
    
    @Bean
    public LocaleResolver localeResolver() {
        SessionLocaleResolver resolver = new SessionLocaleResolver();
        resolver.setDefaultLocale(new Locale("ko", "KR"));
        return resolver;
    }
    
    @Bean
    public LocaleChangeInterceptor localeChangeInterceptor() {
        LocaleChangeInterceptor interceptor = new LocaleChangeInterceptor();
        // URL ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ์–ธ์–ด ๋ณ€๊ฒฝ: ?lang=en
        interceptor.setParamName("lang");
        return interceptor;
    }
    
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(localeChangeInterceptor());
    }
}

๐ŸŽจ Controller์—์„œ ์‚ฌ์šฉํ•˜๊ธฐ

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Locale;

@Controller
public class HomeController {
    
    @Autowired
    private MessageSource messageSource;
    
    @GetMapping("/")
    public String home(Locale locale, Model model) {
        // ํ˜„์žฌ ๋กœ์ผ€์ผ์— ๋งž๋Š” ๋ฉ”์‹œ์ง€ ๊ฐ€์ ธ์˜ค๊ธฐ
        String greeting = messageSource.getMessage(
            "greeting", 
            new Object[]{"์‚ฌ์šฉ์ž"}, 
            locale
        );
        
        String welcomeMessage = messageSource.getMessage(
            "welcome.message", 
            null, 
            locale
        );
        
        model.addAttribute("greeting", greeting);
        model.addAttribute("welcomeMessage", welcomeMessage);
        model.addAttribute("currentLocale", locale);
        
        return "home";
    }
    
    @GetMapping("/profile")
    public String profile(@RequestParam String username, 
                         Locale locale, 
                         Model model) {
        // ๋™์  ๋ฉ”์‹œ์ง€ ์ƒ์„ฑ
        String profileMessage = messageSource.getMessage(
            "profile.welcome",
            new Object[]{username},
            "Welcome to your profile, " + username,  // ๊ธฐ๋ณธ๊ฐ’
            locale
        );
        
        model.addAttribute("message", profileMessage);
        return "profile";
    }
}

๐Ÿ–ผ๏ธ Thymeleaf ํ…œํ”Œ๋ฆฟ์—์„œ ์‚ฌ์šฉํ•˜๊ธฐ

home.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title th:text="#{page.title}">Home</title>
</head>
<body>
    <!-- ์–ธ์–ด ์„ ํƒ ๋ฉ”๋‰ด -->
    <div class="language-selector">
        <a th:href="@{/(lang=ko)}">ํ•œ๊ตญ์–ด</a> |
        <a th:href="@{/(lang=en)}">English</a> |
        <a th:href="@{/(lang=ja)}">ๆ—ฅๆœฌ่ชž</a> |
        <a th:href="@{/(lang=zh)}">ไธญๆ–‡</a>
    </div>
    
    <!-- ๋ฉ”์‹œ์ง€ ํ‘œ์‹œ -->
    <h1 th:text="${greeting}">Greeting</h1>
    <p th:text="${welcomeMessage}">Welcome Message</p>
    
    <!-- ์ง์ ‘ ๋ฉ”์‹œ์ง€ ํ‚ค ์‚ฌ์šฉ -->
    <h2 th:text="#{menu.home}">Home</h2>
    
    <!-- ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ์žˆ๋Š” ๋ฉ”์‹œ์ง€ -->
    <p th:text="#{user.registered(${username}, ${date})}">
        User registered message
    </p>
    
    <!-- ํ˜„์žฌ ๋กœ์ผ€์ผ ํ‘œ์‹œ -->
    <p>Current Locale: <span th:text="${currentLocale}"></span></p>
    
    <!-- ๋ฒ„ํŠผ -->
    <button th:text="#{button.submit}">Submit</button>
    <button th:text="#{button.cancel}">Cancel</button>
</body>
</html>

โšก ์„ฑ๋Šฅ ์ตœ์ ํ™”์™€ ๋ฒ ์ŠคํŠธ ํ”„๋ž™ํ‹ฐ์Šค

๋‹ค๊ตญ์–ด ์ง€์›์„ ๊ตฌํ˜„ํ•  ๋•Œ ์„ฑ๋Šฅ๊ณผ ์œ ์ง€๋ณด์ˆ˜์„ฑ์„ ๊ณ ๋ คํ•ด์•ผ ํ•ด. ๋ช‡ ๊ฐ€์ง€ ์ค‘์š”ํ•œ ํŒ์„ ์•Œ๋ ค์ค„๊ฒŒ! ๐ŸŽฏ

๐Ÿš€ ์„ฑ๋Šฅ ์ตœ์ ํ™” ์ „๋žต

1๏ธโƒฃ ResourceBundle ์บ์‹ฑ ํ™œ์šฉ

ResourceBundle์€ ๊ธฐ๋ณธ์ ์œผ๋กœ ์บ์‹ฑ๋˜์ง€๋งŒ, ๊ฐœ๋ฐœ ์ค‘์—๋Š” ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ์ฆ‰์‹œ ๋ฐ˜์˜ํ•˜๊ณ  ์‹ถ์„ ์ˆ˜ ์žˆ์–ด. ์ด๋Ÿด ๋•Œ๋Š” ResourceBundle.clearCache()๋ฅผ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜, ์ปค์Šคํ…€ Control์„ ๊ตฌํ˜„ํ•ด.

// ์บ์‹œ ํด๋ฆฌ์–ด
ResourceBundle.clearCache();

// ํŠน์ • ํด๋ž˜์Šค๋กœ๋”์˜ ์บ์‹œ๋งŒ ํด๋ฆฌ์–ด
ResourceBundle.clearCache(Thread.currentThread().getContextClassLoader());

2๏ธโƒฃ ์ง€์—ฐ ๋กœ๋”ฉ(Lazy Loading)

๋ชจ๋“  ์–ธ์–ด์˜ ๋ฆฌ์†Œ์Šค๋ฅผ ํ•œ ๋ฒˆ์— ๋กœ๋“œํ•˜์ง€ ๋ง๊ณ , ํ•„์š”ํ•  ๋•Œ๋งŒ ๋กœ๋“œํ•ด. ํŠนํžˆ ๋งŽ์€ ์–ธ์–ด๋ฅผ ์ง€์›ํ•˜๋Š” ๊ฒฝ์šฐ ์ค‘์š”ํ•ด!

public class LocaleManager {
    private Map<Locale, ResourceBundle> bundleCache = new ConcurrentHashMap<>();
    
    public ResourceBundle getBundle(Locale locale) {
        return bundleCache.computeIfAbsent(locale, 
            l -> ResourceBundle.getBundle("messages", l));
    }
}

3๏ธโƒฃ ๋ฌธ์ž์—ด ์—ฐ๊ฒฐ ์ตœ์†Œํ™”

MessageFormat์„ ์‚ฌ์šฉํ•  ๋•Œ ๋ถˆํ•„์š”ํ•œ ๋ฌธ์ž์—ด ์—ฐ๊ฒฐ์„ ํ”ผํ•ด. ํŠนํžˆ ๋ฐ˜๋ณต๋ฌธ ์•ˆ์—์„œ๋Š” ๋”์šฑ ์ฃผ์˜!

// โŒ ๋‚˜์œ ์˜ˆ
String message = "";
for (int i = 0; i < items.size(); i++) {
    message += MessageFormat.format(bundle.getString("item"), items.get(i));
}

// โœ… ์ข‹์€ ์˜ˆ
StringBuilder sb = new StringBuilder();
MessageFormat format = new MessageFormat(bundle.getString("item"));
for (Item item : items) {
    sb.append(format.format(new Object[]{item.getName()}));
}
String message = sb.toString();

๐Ÿ“‹ ๋ฒ ์ŠคํŠธ ํ”„๋ž™ํ‹ฐ์Šค

โœ… DO (ํ•ด์•ผ ํ•  ๊ฒƒ๋“ค)

1. ์ผ๊ด€๋œ ํ‚ค ๋„ค์ด๋ฐ ๊ทœ์น™ ์‚ฌ์šฉ
module.component.action ํ˜•์‹์œผ๋กœ ๊ณ„์ธต์ ์œผ๋กœ ๊ด€๋ฆฌํ•ด. ์˜ˆ: user.profile.edit, order.payment.confirm

2. ๊ธฐ๋ณธ ์–ธ์–ด ํŒŒ์ผ ํ•ญ์ƒ ์ œ๊ณต
messages.properties ํŒŒ์ผ์€ ๋ฐ˜๋“œ์‹œ ๋งŒ๋“ค์–ด. ํด๋ฐฑ์˜ ๋งˆ์ง€๋ง‰ ๋ณด๋ฃจ์•ผ!

3. UTF-8 ์ธ์ฝ”๋”ฉ ์‚ฌ์šฉ
Java 9+ ์—์„œ๋Š” properties ํŒŒ์ผ์ด UTF-8์„ ๊ธฐ๋ณธ์œผ๋กœ ์ง€์›ํ•ด. ์ด์ „ ๋ฒ„์ „์€ native2ascii ๋„๊ตฌ๋ฅผ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ XML ํ˜•์‹์„ ๊ณ ๋ คํ•ด.

4. ๋ฌธ๋งฅ ์ •๋ณด ์ œ๊ณต
๋ฒˆ์—ญ๊ฐ€๋ฅผ ์œ„ํ•ด ์ฃผ์„์œผ๋กœ ๋ฌธ๋งฅ ์ •๋ณด๋ฅผ ์ œ๊ณตํ•ด:

# ์‚ฌ์šฉ์ž ํ”„๋กœํ•„ ํŽ˜์ด์ง€์˜ ํ™˜์˜ ๋ฉ”์‹œ์ง€
# {0}: ์‚ฌ์šฉ์ž ์ด๋ฆ„
user.welcome=Welcome back, {0}!

# ์ฃผ๋ฌธ ํ™•์ธ ๋ฒ„ํŠผ (๊ฒฐ์ œ ํŽ˜์ด์ง€)
order.confirm.button=Confirm Order

5. ๋ณต์ˆ˜ํ˜• ์ฒ˜๋ฆฌ
ChoiceFormat์„ ์‚ฌ์šฉํ•ด์„œ ๋ณต์ˆ˜ํ˜•์„ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์ฒ˜๋ฆฌํ•ด:

# ์˜์–ด
items.count={0,choice,0#No items|1#One item|1<{0,number,integer} items}

# ํ•œ๊ตญ์–ด (๋ณต์ˆ˜ํ˜• ๊ตฌ๋ถ„ ์—†์Œ)
items.count={0}๊ฐœ์˜ ํ•ญ๋ชฉ
โŒ DON'T (ํ•˜์ง€ ๋ง์•„์•ผ ํ•  ๊ฒƒ๋“ค)

1. ํ•˜๋“œ์ฝ”๋”ฉ ์ ˆ๋Œ€ ๊ธˆ์ง€
์ฝ”๋“œ์— ์ง์ ‘ ๋ฌธ์ž์—ด์„ ๋„ฃ์ง€ ๋งˆ! ๋‚˜์ค‘์— ์ฐพ์•„์„œ ๋ฐ”๊พธ๊ธฐ ์ •๋ง ํž˜๋“ค์–ด.

2. ๋ฌธ์ž์—ด ์—ฐ๊ฒฐ๋กœ ๋ฌธ์žฅ ๋งŒ๋“ค๊ธฐ
์–ธ์–ด๋งˆ๋‹ค ์–ด์ˆœ์ด ๋‹ค๋ฅด๋‹ˆ๊นŒ ๋ฌธ์ž์—ด์„ ์กฐ๊ฐ๋‚ด์„œ ์—ฐ๊ฒฐํ•˜๋ฉด ์•ˆ ๋ผ:

// โŒ ๋‚˜์œ ์˜ˆ
String message = bundle.getString("hello") + " " + username + " " + bundle.getString("welcome");

// โœ… ์ข‹์€ ์˜ˆ
String message = MessageFormat.format(bundle.getString("greeting"), username);

3. ๋‚ ์งœ/์ˆซ์ž๋ฅผ ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜ ํ›„ ์ €์žฅ
ํ•ญ์ƒ ์›๋ณธ ๋ฐ์ดํ„ฐ ํƒ€์ž…์„ ์œ ์ง€ํ•˜๊ณ , ํ‘œ์‹œํ•  ๋•Œ๋งŒ ํฌ๋งทํŒ…ํ•ด.

4. ๋กœ์ผ€์ผ์„ ํ•˜๋“œ์ฝ”๋”ฉ
new Locale("ko", "KR") ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ์—ฌ๊ธฐ์ €๊ธฐ ํฉ๋ฟŒ๋ฆฌ์ง€ ๋งˆ. ์ค‘์•™์—์„œ ๊ด€๋ฆฌํ•ด!

๐Ÿ”ง ์‹ค๋ฌด ํŒ: ๋ฒˆ์—ญ ๊ด€๋ฆฌ ์ „๋žต

์‹ค์ œ ํ”„๋กœ์ ํŠธ์—์„œ๋Š” ์ˆ˜๋ฐฑ, ์ˆ˜์ฒœ ๊ฐœ์˜ ๋ฒˆ์—ญ ํ‚ค๋ฅผ ๊ด€๋ฆฌํ•ด์•ผ ํ•ด. ํšจ์œจ์ ์ธ ๊ด€๋ฆฌ ์ „๋žต์ด ํ•„์ˆ˜์•ผ! ๐Ÿ“Š

๐Ÿ“ ํŒŒ์ผ ๊ตฌ์กฐ ์กฐ์งํ™”

๋ชจ๋“  ๋ฒˆ์—ญ์„ ํ•˜๋‚˜์˜ ํŒŒ์ผ์— ๋„ฃ์œผ๋ฉด ๊ด€๋ฆฌ๊ฐ€ ์–ด๋ ค์›Œ. ๋ชจ๋“ˆ๋ณ„๋กœ ๋ถ„๋ฆฌํ•˜๋Š” ๊ฒŒ ์ข‹์•„:

resources/
  โ”œโ”€โ”€ i18n/
  โ”‚   โ”œโ”€โ”€ common/
  โ”‚   โ”‚   โ”œโ”€โ”€ messages.properties
  โ”‚   โ”‚   โ”œโ”€โ”€ messages_ko.properties
  โ”‚   โ”‚   โ””โ”€โ”€ messages_en.properties
  โ”‚   โ”œโ”€โ”€ user/
  โ”‚   โ”‚   โ”œโ”€โ”€ user.properties
  โ”‚   โ”‚   โ”œโ”€โ”€ user_ko.properties
  โ”‚   โ”‚   โ””โ”€โ”€ user_en.properties
  โ”‚   โ”œโ”€โ”€ order/
  โ”‚   โ”‚   โ”œโ”€โ”€ order.properties
  โ”‚   โ”‚   โ”œโ”€โ”€ order_ko.properties
  โ”‚   โ”‚   โ””โ”€โ”€ order_en.properties
  โ”‚   โ””โ”€โ”€ error/
  โ”‚       โ”œโ”€โ”€ errors.properties
  โ”‚       โ”œโ”€โ”€ errors_ko.properties
  โ”‚       โ””โ”€โ”€ errors_en.properties
// ์—ฌ๋Ÿฌ ๋ฒˆ๋“ค์„ ์กฐํ•ฉํ•ด์„œ ์‚ฌ์šฉ
public class MultiResourceBundleManager {
    
    private List<ResourceBundle> bundles;
    
    public MultiResourceBundleManager(Locale locale) {
        bundles = Arrays.asList(
            ResourceBundle.getBundle("i18n/common/messages", locale),
            ResourceBundle.getBundle("i18n/user/user", locale),
            ResourceBundle.getBundle("i18n/order/order", locale),
            ResourceBundle.getBundle("i18n/error/errors", locale)
        );
    }
    
    public String getString(String key) {
        for (ResourceBundle bundle : bundles) {
            try {
                return bundle.getString(key);
            } catch (MissingResourceException e) {
                // ๋‹ค์Œ ๋ฒˆ๋“ค์—์„œ ์ฐพ๊ธฐ
            }
        }
        throw new MissingResourceException(
            "Key not found in any bundle", 
            "MultiResourceBundle", 
            key
        );
    }
}

๐Ÿ› ๏ธ ๋ฒˆ์—ญ ๊ฒ€์ฆ ๋„๊ตฌ ๋งŒ๋“ค๊ธฐ

๋ฒˆ์—ญ์ด ๋ˆ„๋ฝ๋˜๊ฑฐ๋‚˜ ์ž˜๋ชป๋œ ๊ฑธ ์ž๋™์œผ๋กœ ์ฐพ์•„์ฃผ๋Š” ๋„๊ตฌ๋ฅผ ๋งŒ๋“ค๋ฉด ์ •๋ง ์œ ์šฉํ•ด! ๐Ÿ”

import java.io.*;
import java.util.*;

public class TranslationValidator {
    
    public static void main(String[] args) throws IOException {
        String basePath = "src/main/resources/";
        String baseName = "messages";
        
        // ๊ธฐ๋ณธ ํŒŒ์ผ ๋กœ๋“œ
        Properties baseProps = loadProperties(basePath + baseName + ".properties");
        
        // ๋‹ค๋ฅธ ์–ธ์–ด ํŒŒ์ผ๋“ค ๊ฒ€์ฆ
        String[] locales = {"ko", "ja", "zh", "en"};
        
        for (String locale : locales) {
            String fileName = baseName + "_" + locale + ".properties";
            Properties localeProps = loadProperties(basePath + fileName);
            
            System.out.println("\n=== " + locale + " ๊ฒ€์ฆ ===");
            
            // ๋ˆ„๋ฝ๋œ ํ‚ค ์ฐพ๊ธฐ
            Set<String> missingKeys = new HashSet<>(baseProps.stringPropertyNames());
            missingKeys.removeAll(localeProps.stringPropertyNames());
            
            if (!missingKeys.isEmpty()) {
                System.out.println("โŒ ๋ˆ„๋ฝ๋œ ํ‚ค (" + missingKeys.size() + "๊ฐœ):");
                missingKeys.forEach(key -> System.out.println("  - " + key));
            }
            
            // ์ถ”๊ฐ€๋œ ํ‚ค ์ฐพ๊ธฐ (๊ธฐ๋ณธ ํŒŒ์ผ์— ์—†๋Š” ํ‚ค)
            Set<String> extraKeys = new HashSet<>(localeProps.stringPropertyNames());
            extraKeys.removeAll(baseProps.stringPropertyNames());
            
            if (!extraKeys.isEmpty()) {
                System.out.println("โš ๏ธ  ์ถ”๊ฐ€๋œ ํ‚ค (" + extraKeys.size() + "๊ฐœ):");
                extraKeys.forEach(key -> System.out.println("  - " + key));
            }
            
            // ๋นˆ ๊ฐ’ ์ฐพ๊ธฐ
            List<String> emptyValues = new ArrayList<>();
            for (String key : localeProps.stringPropertyNames()) {
                if (localeProps.getProperty(key).trim().isEmpty()) {
                    emptyValues.add(key);
                }
            }
            
            if (!emptyValues.isEmpty()) {
                System.out.println("โš ๏ธ  ๋นˆ ๊ฐ’ (" + emptyValues.size() + "๊ฐœ):");
                emptyValues.forEach(key -> System.out.println("  - " + key));
            }
            
            if (missingKeys.isEmpty() && extraKeys.isEmpty() && emptyValues.isEmpty()) {
                System.out.println("โœ… ๋ชจ๋“  ๊ฒ€์ฆ ํ†ต๊ณผ!");
            }
        }
    }
    
    private static Properties loadProperties(String filePath) throws IOException {
        Properties props = new Properties();
        try (InputStream input = new FileInputStream(filePath)) {
            props.load(input);
        }
        return props;
    }
}

๐ŸŒ ๋ฒˆ์—ญ ๊ด€๋ฆฌ ํ”Œ๋žซํผ ํ™œ์šฉ

๋Œ€๊ทœ๋ชจ ํ”„๋กœ์ ํŠธ์—์„œ๋Š” ์ „๋ฌธ ๋ฒˆ์—ญ ๊ด€๋ฆฌ ํ”Œ๋žซํผ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒŒ ์ข‹์•„. ๋ช‡ ๊ฐ€์ง€ ์ถ”์ฒœํ• ๊ฒŒ:

๐Ÿ”น Crowdin ๊ฐœ๋ฐœ์ž์™€ ๋ฒˆ์—ญ๊ฐ€๊ฐ€ ํ˜‘์—…ํ•˜๊ธฐ ์ข‹์€ ํ”Œ๋žซํผ. GitHub ์—ฐ๋™์ด ์ž˜ ๋˜์–ด ์žˆ์–ด์„œ ์ž๋™ํ™”ํ•˜๊ธฐ ํŽธํ•ด.

๐Ÿ”น Lokalise
UI๊ฐ€ ์ง๊ด€์ ์ด๊ณ , ๋ฒˆ์—ญ ๋ฉ”๋ชจ๋ฆฌ ๊ธฐ๋Šฅ์ด ๊ฐ•๋ ฅํ•ด. API๋„ ์ž˜ ๋˜์–ด ์žˆ์–ด์„œ CI/CD์— ํ†ตํ•ฉํ•˜๊ธฐ ์ข‹์•„.

๐Ÿ”น Phrase
์—”ํ„ฐํ”„๋ผ์ด์ฆˆ๊ธ‰ ๊ธฐ๋Šฅ์ด ๋งŽ๊ณ , ํ’ˆ์งˆ ๊ด€๋ฆฌ ๋„๊ตฌ๊ฐ€ ํ›Œ๋ฅญํ•ด. ๋Œ€๊ทœ๋ชจ ํŒ€์— ์ ํ•ฉํ•ด.

๐Ÿ”น POEditor
๊ฐ€๊ฒฉ์ด ์ €๋ ดํ•˜๊ณ  ์‚ฌ์šฉํ•˜๊ธฐ ์‰ฌ์›Œ. ์†Œ๊ทœ๋ชจ ํ”„๋กœ์ ํŠธ๋‚˜ ์Šคํƒ€ํŠธ์—…์— ์ข‹์•„.

๐Ÿ› ํ”ํ•œ ๋ฌธ์ œ์™€ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

๋‹ค๊ตญ์–ด ์ง€์›์„ ๊ตฌํ˜„ํ•˜๋‹ค ๋ณด๋ฉด ์—ฌ๋Ÿฌ ๊ฐ€์ง€ ๋ฌธ์ œ์— ๋ถ€๋”ชํž ์ˆ˜ ์žˆ์–ด. ์ž์ฃผ ๋ฐœ์ƒํ•˜๋Š” ๋ฌธ์ œ๋“ค๊ณผ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณด์ž! ๐Ÿ”ง

โ“ ๋ฌธ์ œ 1: ํ•œ๊ธ€์ด ๊นจ์ ธ์š”!

์ฆ์ƒ: properties ํŒŒ์ผ์— ํ•œ๊ธ€์„ ์ž…๋ ฅํ–ˆ๋Š”๋ฐ ์‹คํ–‰ํ•˜๋ฉด ??? ๋˜๋Š” ๊นจ์ง„ ๋ฌธ์ž๋กœ ๋‚˜์™€์š”.
ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•:

Java 8 ์ดํ•˜: native2ascii ๋„๊ตฌ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์œ ๋‹ˆ์ฝ”๋“œ ์ด์Šค์ผ€์ดํ”„ ์‹œํ€€์Šค๋กœ ๋ณ€ํ™˜ํ•ด์•ผ ํ•ด.

# ๋ช…๋ น์–ด
native2ascii -encoding UTF-8 messages_ko.properties messages_ko_escaped.properties

# ๋˜๋Š” IntelliJ IDEA ์„ค์ •์—์„œ
# Settings โ†’ Editor โ†’ File Encodings โ†’ Transparent native-to-ascii conversion ์ฒดํฌ

Java 9 ์ด์ƒ: properties ํŒŒ์ผ์ด UTF-8์„ ๊ธฐ๋ณธ์œผ๋กœ ์ง€์›ํ•˜๋‹ˆ๊นŒ ๊ทธ๋ƒฅ ์‚ฌ์šฉํ•˜๋ฉด ๋ผ!

Spring Boot: application.properties์— ์ธ์ฝ”๋”ฉ ์„ค์ • ์ถ”๊ฐ€:

spring.messages.encoding=UTF-8

โ“ ๋ฌธ์ œ 2: MissingResourceException์ด ๋ฐœ์ƒํ•ด์š”!

์ฆ์ƒ:
java.util.MissingResourceException: Can't find bundle
์—๋Ÿฌ๊ฐ€ ๋‚˜์š”.
ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•:

1. ํŒŒ์ผ ์œ„์น˜ ํ™•์ธ
properties ํŒŒ์ผ์ด ํด๋ž˜์ŠคํŒจ์Šค์— ์žˆ๋Š”์ง€ ํ™•์ธํ•ด. Maven/Gradle ํ”„๋กœ์ ํŠธ๋ผ๋ฉด src/main/resources์— ์žˆ์–ด์•ผ ํ•ด.

2. ํŒŒ์ผ ์ด๋ฆ„ ํ™•์ธ
basename_์–ธ์–ด_๊ตญ๊ฐ€.properties ํ˜•์‹์ด ์ •ํ™•ํ•œ์ง€ ํ™•์ธํ•ด. ๋Œ€์†Œ๋ฌธ์ž๋„ ์ค‘์š”ํ•ด!

3. ๊ธฐ๋ณธ ํŒŒ์ผ ํ™•์ธ
messages.properties (์–ธ์–ด ์ฝ”๋“œ ์—†๋Š” ๊ธฐ๋ณธ ํŒŒ์ผ)์ด ์žˆ๋Š”์ง€ ํ™•์ธํ•ด.

4. ๋นŒ๋“œ ์„ค์ • ํ™•์ธ
Maven์ด๋‚˜ Gradle์—์„œ ๋ฆฌ์†Œ์Šค ํŒŒ์ผ์ด ์ œ๋Œ€๋กœ ๋ณต์‚ฌ๋˜๋Š”์ง€ ํ™•์ธํ•ด:

<!-- Maven pom.xml -->
<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.properties</include>
            </includes>
        </resource>
    </resources>
</build>

โ“ ๋ฌธ์ œ 3: ๋กœ์ผ€์ผ์ด ์ž๋™์œผ๋กœ ๋ณ€๊ฒฝ๋˜์ง€ ์•Š์•„์š”!

์ฆ์ƒ: ๋ธŒ๋ผ์šฐ์ € ์–ธ์–ด๋ฅผ ๋ฐ”๊ฟ”๋„ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์–ธ์–ด๊ฐ€ ๋ฐ”๋€Œ์ง€ ์•Š์•„์š”.
ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•:

์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๊ฒฝ์šฐ: LocaleResolver๋ฅผ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์„ค์ •ํ–ˆ๋Š”์ง€ ํ™•์ธํ•ด.

@Bean
public LocaleResolver localeResolver() {
    // AcceptHeaderLocaleResolver: HTTP Accept-Language ํ—ค๋” ์‚ฌ์šฉ
    AcceptHeaderLocaleResolver resolver = new AcceptHeaderLocaleResolver();
    resolver.setDefaultLocale(Locale.KOREAN);
    return resolver;
    
    // ๋˜๋Š” SessionLocaleResolver: ์„ธ์…˜์— ์ €์žฅ
    // SessionLocaleResolver resolver = new SessionLocaleResolver();
    // resolver.setDefaultLocale(Locale.KOREAN);
    // return resolver;
    
    // ๋˜๋Š” CookieLocaleResolver: ์ฟ ํ‚ค์— ์ €์žฅ
    // CookieLocaleResolver resolver = new CookieLocaleResolver();
    // resolver.setDefaultLocale(Locale.KOREAN);
    // resolver.setCookieName("language");
    // resolver.setCookieMaxAge(3600);
    // return resolver;
}

โ“ ๋ฌธ์ œ 4: MessageFormat ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ ์ œ๋Œ€๋กœ ์น˜ํ™˜๋˜์ง€ ์•Š์•„์š”!

์ฆ์ƒ: {0}, {1} ๊ฐ™์€ ํ”Œ๋ ˆ์ด์Šคํ™€๋”๊ฐ€ ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅ๋ผ์š”.
ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•:

1. MessageFormat ์‚ฌ์šฉ ํ™•์ธ
๋‹จ์ˆœํžˆ getString()๋งŒ ํ˜ธ์ถœํ•˜๋ฉด ์น˜ํ™˜์ด ์•ˆ ๋ผ. MessageFormat.format()์„ ์‚ฌ์šฉํ•ด์•ผ ํ•ด!

// โŒ ์ž˜๋ชป๋œ ๋ฐฉ๋ฒ•
String message = bundle.getString("greeting");

// โœ… ์˜ฌ๋ฐ”๋ฅธ ๋ฐฉ๋ฒ•
String pattern = bundle.getString("greeting");
String message = MessageFormat.format(pattern, "ํ™๊ธธ๋™");

2. ์ž‘์€๋”ฐ์˜ดํ‘œ ์ด์Šค์ผ€์ดํ”„
MessageFormat์—์„œ ์ž‘์€๋”ฐ์˜ดํ‘œ(')๋Š” ํŠน์ˆ˜ ๋ฌธ์ž์•ผ. ๋ฌธ์ž ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ๋‘ ๋ฒˆ ์จ์•ผ ํ•ด:

# โŒ ์ž˜๋ชป๋œ ์˜ˆ
message=It's {0}'s birthday

# โœ… ์˜ฌ๋ฐ”๋ฅธ ์˜ˆ
message=It''s {0}''s birthday

๐ŸŽ“ ๊ณ ๊ธ‰ ์ฃผ์ œ: ๋™์  ๋กœ์ผ€์ผ ์ „ํ™˜

์‚ฌ์šฉ์ž๊ฐ€ ์‹ค์‹œ๊ฐ„์œผ๋กœ ์–ธ์–ด๋ฅผ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•ด๋ณด์ž! ์žฌ๋Šฅ๋„ท ๊ฐ™์€ ํ”Œ๋žซํผ์—์„œ ์‚ฌ์šฉ์ž ๊ฒฝํ—˜์„ ํฌ๊ฒŒ ํ–ฅ์ƒ์‹œํ‚ฌ ์ˆ˜ ์žˆ์–ด. ๐ŸŒŸ

๐Ÿ”„ ์‹ค์‹œ๊ฐ„ ์–ธ์–ด ์ „ํ™˜ ๊ตฌํ˜„

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public class LocaleManager {
    
    private static LocaleManager instance;
    private Locale currentLocale;
    private Map<Locale, ResourceBundle> bundleCache;
    private List<LocaleChangeListener> listeners;
    
    private LocaleManager() {
        this.currentLocale = Locale.getDefault();
        this.bundleCache = new ConcurrentHashMap<>();
        this.listeners = new ArrayList<>();
    }
    
    public static synchronized LocaleManager getInstance() {
        if (instance == null) {
            instance = new LocaleManager();
        }
        return instance;
    }
    
    public Locale getCurrentLocale() {
        return currentLocale;
    }
    
    public void setCurrentLocale(Locale locale) {
        if (!currentLocale.equals(locale)) {
            Locale oldLocale = currentLocale;
            currentLocale = locale;
            notifyListeners(oldLocale, locale);
        }
    }
    
    public ResourceBundle getBundle(String baseName) {
        return bundleCache.computeIfAbsent(
            currentLocale,
            locale -> ResourceBundle.getBundle(baseName, locale)
        );
    }
    
    public String getMessage(String key, Object... args) {
        ResourceBundle bundle = getBundle("messages");
        String pattern = bundle.getString(key);
        
        if (args.length > 0) {
            return MessageFormat.format(pattern, args);
        }
        return pattern;
    }
    
    public void addLocaleChangeListener(LocaleChangeListener listener) {
        listeners.add(listener);
    }
    
    public void removeLocaleChangeListener(LocaleChangeListener listener) {
        listeners.remove(listener);
    }
    
    private void notifyListeners(Locale oldLocale, Locale newLocale) {
        LocaleChangeEvent event = new LocaleChangeEvent(oldLocale, newLocale);
        for (LocaleChangeListener listener : listeners) {
            listener.onLocaleChanged(event);
        }
    }
    
    public void clearCache() {
        bundleCache.clear();
        ResourceBundle.clearCache();
    }
}

// ๋ฆฌ์Šค๋„ˆ ์ธํ„ฐํŽ˜์ด์Šค
interface LocaleChangeListener {
    void onLocaleChanged(LocaleChangeEvent event);
}

// ์ด๋ฒคํŠธ ํด๋ž˜์Šค
class LocaleChangeEvent {
    private final Locale oldLocale;
    private final Locale newLocale;
    
    public LocaleChangeEvent(Locale oldLocale, Locale newLocale) {
        this.oldLocale = oldLocale;
        this.newLocale = newLocale;
    }
    
    public Locale getOldLocale() { return oldLocale; }
    public Locale getNewLocale() { return newLocale; }
}

๐ŸŽจ GUI ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ์‚ฌ์šฉํ•˜๊ธฐ

import javax.swing.*;
import java.awt.*;
import java.util.Locale;

public class MultilingualApp extends JFrame implements LocaleChangeListener {
    
    private JLabel titleLabel;
    private JButton submitButton;
    private JButton cancelButton;
    private JComboBox<String> languageCombo;
    
    private LocaleManager localeManager;
    
    public MultilingualApp() {
        localeManager = LocaleManager.getInstance();
        localeManager.addLocaleChangeListener(this);
        
        initComponents();
        updateTexts();
    }
    
    private void initComponents() {
        setTitle("Multilingual Application");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLayout(new BorderLayout(10, 10));
        
        // ์–ธ์–ด ์„ ํƒ ํŒจ๋„
        JPanel topPanel = new JPanel();
        topPanel.add(new JLabel("Language:"));
        
        String[] languages = {"ํ•œ๊ตญ์–ด", "English", "ๆ—ฅๆœฌ่ชž", "ไธญๆ–‡"};
        languageCombo = new JComboBox<>(languages);
        languageCombo.addActionListener(e -> changeLanguage());
        topPanel.add(languageCombo);
        
        add(topPanel, BorderLayout.NORTH);
        
        // ๋ฉ”์ธ ์ปจํ…์ธ 
        JPanel centerPanel = new JPanel(new GridLayout(3, 1, 10, 10));
        centerPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        
        titleLabel = new JLabel();
        titleLabel.setFont(new Font("Dialog", Font.BOLD, 18));
        centerPanel.add(titleLabel);
        
        submitButton = new JButton();
        cancelButton = new JButton();
        
        centerPanel.add(submitButton);
        centerPanel.add(cancelButton);
        
        add(centerPanel, BorderLayout.CENTER);
        
        pack();
        setSize(400, 250);
        setLocationRelativeTo(null);
    }
    
    private void changeLanguage() {
        int index = languageCombo.getSelectedIndex();
        Locale newLocale;
        
        switch (index) {
            case 0: newLocale = new Locale("ko", "KR"); break;
            case 1: newLocale = Locale.US; break;
            case 2: newLocale = Locale.JAPAN; break;
            case 3: newLocale = Locale.CHINA; break;
            default: newLocale = Locale.getDefault();
        }
        
        localeManager.setCurrentLocale(newLocale);
    }
    
    private void updateTexts() {
        titleLabel.setText(localeManager.getMessage("welcome.message"));
        submitButton.setText(localeManager.getMessage("button.submit"));
        cancelButton.setText(localeManager.getMessage("button.cancel"));
    }
    
    @Override
    public void onLocaleChanged(LocaleChangeEvent event) {
        // ๋กœ์ผ€์ผ์ด ๋ณ€๊ฒฝ๋˜๋ฉด ๋ชจ๋“  ํ…์ŠคํŠธ ์—…๋ฐ์ดํŠธ
        SwingUtilities.invokeLater(this::updateTexts);
        
        System.out.println("Language changed from " + 
            event.getOldLocale().getDisplayLanguage() + " to " +
            event.getNewLocale().getDisplayLanguage());
    }
    
    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            new MultilingualApp().setVisible(true);
        });
    }
}

๐ŸŒŸ ์‹ค์ „ ์˜ˆ์ œ: ์™„์ „ํ•œ ๋‹ค๊ตญ์–ด ์ง€์› ์‹œ์Šคํ…œ

์ง€๊ธˆ๊นŒ์ง€ ๋ฐฐ์šด ๋‚ด์šฉ์„ ๋ชจ๋‘ ์ข…ํ•ฉํ•ด์„œ ์‹ค์ œ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์™„์ „ํ•œ ์‹œ์Šคํ…œ์„ ๋งŒ๋“ค์–ด๋ณด์ž! ๐Ÿš€

import java.text.*;
import java.util.*;

/**
 * ์™„์ „ํ•œ ๊ตญ์ œํ™” ์ง€์› ์œ ํ‹ธ๋ฆฌํ‹ฐ ํด๋ž˜์Šค
 */
public class I18nUtil {
    
    private static final String DEFAULT_BUNDLE_NAME = "messages";
    private Locale currentLocale;
    private ResourceBundle bundle;
    
    public I18nUtil() {
        this(Locale.getDefault());
    }
    
    public I18nUtil(Locale locale) {
        setLocale(locale);
    }
    
    public void setLocale(Locale locale) {
        this.currentLocale = locale;
        this.bundle = ResourceBundle.getBundle(DEFAULT_BUNDLE_NAME, locale);
    }
    
    public Locale getCurrentLocale() {
        return currentLocale;
    }
    
    /**
     * ๋‹จ์ˆœ ๋ฉ”์‹œ์ง€ ๊ฐ€์ ธ์˜ค๊ธฐ
     */
    public String getMessage(String key) {
        try {
            return bundle.getString(key);
        } catch (MissingResourceException e) {
            return "???" + key + "???";
        }
    }
    
    /**
     * ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ์žˆ๋Š” ๋ฉ”์‹œ์ง€ ๊ฐ€์ ธ์˜ค๊ธฐ
     */
    public String getMessage(String key, Object... args) {
        String pattern = getMessage(key);
        return MessageFormat.format(pattern, args);
    }
    
    /**
     * ๋‚ ์งœ ํฌ๋งทํŒ…
     */
    public String formatDate(Date date, int style) {
        DateFormat formatter = DateFormat.getDateInstance(style, currentLocale);
        return formatter.format(date);
    }
    
    public String formatDate(Date date) {
        return formatDate(date, DateFormat.MEDIUM);
    }
    
    /**
     * ์‹œ๊ฐ„ ํฌ๋งทํŒ…
     */
    public String formatTime(Date date, int style) {
        DateFormat formatter = DateFormat.getTimeInstance(style, currentLocale);
        return formatter.format(date);
    }
    
    public String formatTime(Date date) {
        return formatTime(date, DateFormat.MEDIUM);
    }
    
    /**
     * ๋‚ ์งœ+์‹œ๊ฐ„ ํฌ๋งทํŒ…
     */
    public String formatDateTime(Date date, int dateStyle, int timeStyle) {
        DateFormat formatter = DateFormat.getDateTimeInstance(
            dateStyle, timeStyle, currentLocale
        );
        return formatter.format(date);
    }
    
    public String formatDateTime(Date date) {
        return formatDateTime(date, DateFormat.MEDIUM, DateFormat.MEDIUM);
    }
    
    /**
     * ์ˆซ์ž ํฌ๋งทํŒ…
     */
    public String formatNumber(Number number) {
        NumberFormat formatter = NumberFormat.getNumberInstance(currentLocale);
        return formatter.format(number);
    }
    
    public String formatNumber(Number number, int minDecimals, int maxDecimals) {
        NumberFormat formatter = NumberFormat.getNumberInstance(currentLocale);
        formatter.setMinimumFractionDigits(minDecimals);
        formatter.setMaximumFractionDigits(maxDecimals);
        return formatter.format(number);
    }
    
    /**
     * ํ†ตํ™” ํฌ๋งทํŒ…
     */
    public String formatCurrency(Number amount) {
        NumberFormat formatter = NumberFormat.getCurrencyInstance(currentLocale);
        return formatter.format(amount);
    }
    
    /**
     * ํผ์„ผํŠธ ํฌ๋งทํŒ…
     */
    public String formatPercent(Number value) {
        NumberFormat formatter = NumberFormat.getPercentInstance(currentLocale);
        return formatter.format(value);
    }
    
    /**
     * ๋ณต์ˆ˜ํ˜• ์ฒ˜๋ฆฌ
     */
    public String getPlural(String key, int count) {
        String pattern = getMessage(key);
        MessageFormat formatter = new MessageFormat(pattern, currentLocale);
        return formatter.format(new Object[]{count});
    }
    
    /**
     * ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ๋กœ์ผ€์ผ ๊ฐ€์ ธ์˜ค๊ธฐ
     */
    public static List<Locale> getAvailableLocales() {
        return Arrays.asList(Locale.getAvailableLocales());
    }
    
    /**
     * ์ง€์›ํ•˜๋Š” ์–ธ์–ด ๋ชฉ๋ก ๊ฐ€์ ธ์˜ค๊ธฐ
     */
    public static List<Locale> getSupportedLocales() {
        return Arrays.asList(
            new Locale("ko", "KR"),
            Locale.US,
            Locale.JAPAN,
            Locale.CHINA,
            Locale.FRANCE,
            Locale.GERMANY
        );
    }
}

๐Ÿ’ป ์‚ฌ์šฉ ์˜ˆ์ œ

public class I18nDemo {
    
    public static void main(String[] args) {
        // ํ•œ๊ตญ์–ด๋กœ ์‹œ์ž‘
        I18nUtil i18n = new I18nUtil(new Locale("ko", "KR"));
        
        System.out.println("=== ํ•œ๊ตญ์–ด ===");
        demonstrateFeatures(i18n);
        
        // ์˜์–ด๋กœ ๋ณ€๊ฒฝ
        i18n.setLocale(Locale.US);
        System.out.println("\n=== English ===");
        demonstrateFeatures(i18n);
        
        // ์ผ๋ณธ์–ด๋กœ ๋ณ€๊ฒฝ
        i18n.setLocale(Locale.JAPAN);
        System.out.println("\n=== ๆ—ฅๆœฌ่ชž ===");
        demonstrateFeatures(i18n);
    }
    
    private static void demonstrateFeatures(I18nUtil i18n) {
        // ๋‹จ์ˆœ ๋ฉ”์‹œ์ง€
        System.out.println("ํ™˜์˜ ๋ฉ”์‹œ์ง€: " + i18n.getMessage("welcome.message"));
        
        // ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ์žˆ๋Š” ๋ฉ”์‹œ์ง€
        System.out.println("์ธ์‚ฌ: " + i18n.getMessage("greeting", "ํ™๊ธธ๋™"));
        
        // ๋‚ ์งœ ํฌ๋งทํŒ…
        Date now = new Date();
        System.out.println("๋‚ ์งœ: " + i18n.formatDate(now));
        System.out.println("์‹œ๊ฐ„: " + i18n.formatTime(now));
        System.out.println("๋‚ ์งœ+์‹œ๊ฐ„: " + i18n.formatDateTime(now));
        
        // ์ˆซ์ž ํฌ๋งทํŒ…
        double number = 1234567.89;
        System.out.println("์ˆซ์ž: " + i18n.formatNumber(number));
        System.out.println("ํ†ตํ™”: " + i18n.formatCurrency(number));
        
        // ํผ์„ผํŠธ ํฌ๋งทํŒ…
        double percent = 0.75;
        System.out.println("ํผ์„ผํŠธ: " + i18n.formatPercent(percent));
        
        // ๋ณต์ˆ˜ํ˜• ์ฒ˜๋ฆฌ
        System.out.println("ํ•ญ๋ชฉ 1๊ฐœ: " + i18n.getPlural("items.count", 1));
        System.out.println("ํ•ญ๋ชฉ 5๊ฐœ: " + i18n.getPlural("items.count", 5));
    }
}

๐ŸŽฏ ๋งˆ๋ฌด๋ฆฌํ•˜๋ฉฐ

์ž, ์—ฌ๊ธฐ๊นŒ์ง€ ์ž๋ฐ”์˜ ๊ตญ์ œํ™”์™€ ResourceBundle์— ๋Œ€ํ•ด ๊นŠ์ด ์žˆ๊ฒŒ ์•Œ์•„๋ดค์–ด! ์ •๋ง ๋งŽ์€ ๋‚ด์šฉ์„ ๋‹ค๋ค˜์ง€? ๐Ÿ˜Š

๋‹ค๊ตญ์–ด ์ง€์›์€ ๋‹จ์ˆœํžˆ ํ…์ŠคํŠธ๋ฅผ ๋ฒˆ์—ญํ•˜๋Š” ๊ฒƒ ์ด์ƒ์ด์•ผ. ์‚ฌ์šฉ์ž์˜ ๋ฌธํ™”์™€ ๊ด€์Šต์„ ์กด์ค‘ํ•˜๊ณ , ์ „ ์„ธ๊ณ„ ๋ˆ„๊ตฌ๋‚˜ ํŽธํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋งŒ๋“œ๋Š” ๊ฑฐ์ง€. ๐ŸŒ

๐Ÿ“š ํ•ต์‹ฌ ์š”์•ฝ

1๏ธโƒฃ ResourceBundle
์ž๋ฐ”์˜ ๊ตญ์ œํ™” ํ•ต์‹ฌ ๋„๊ตฌ. properties ํŒŒ์ผ์ด๋‚˜ ์ž๋ฐ” ํด๋ž˜์Šค๋กœ ์–ธ์–ด๋ณ„ ๋ฆฌ์†Œ์Šค๋ฅผ ๊ด€๋ฆฌํ•ด.

2๏ธโƒฃ Locale
์–ธ์–ด์™€ ์ง€์—ญ์„ ๋‚˜ํƒ€๋‚ด๋Š” ๊ฐ์ฒด. ์–ธ์–ด, ๊ตญ๊ฐ€, ๋ณ€ํ˜•์œผ๋กœ ์„ธ๋ฐ€ํ•˜๊ฒŒ ๊ตฌ๋ถ„ํ•  ์ˆ˜ ์žˆ์–ด.

3๏ธโƒฃ MessageFormat
๋™์ ์ธ ๊ฐ’์„ ๋ฉ”์‹œ์ง€์— ํฌํ•จํ•  ๋•Œ ์‚ฌ์šฉ. ๋ณต์ˆ˜ํ˜•, ๋‚ ์งœ, ์ˆซ์ž ๋“ฑ ๋‹ค์–‘ํ•œ ํฌ๋งท ์ง€์›.

4๏ธโƒฃ ํด๋ฐฑ ๋ฉ”์ปค๋‹ˆ์ฆ˜
ํŠน์ • ์–ธ์–ด ๋ฆฌ์†Œ์Šค๊ฐ€ ์—†์œผ๋ฉด ์ž๋™์œผ๋กœ ์ƒ์œ„ ์–ธ์–ด๋‚˜ ๊ธฐ๋ณธ ์–ธ์–ด๋กœ ๋Œ์•„๊ฐ€.

5๏ธโƒฃ ํฌ๋งทํŒ…
DateFormat, NumberFormat ๋“ฑ์œผ๋กœ ๋‚ ์งœ, ์‹œ๊ฐ„, ์ˆซ์ž, ํ†ตํ™”๋ฅผ ๋กœ์ผ€์ผ์— ๋งž๊ฒŒ ํ‘œ์‹œ.

๐Ÿš€ ๋‹ค์Œ ๋‹จ๊ณ„

์ด์ œ ๋ฐฐ์šด ๋‚ด์šฉ์„ ์‹ค์ œ ํ”„๋กœ์ ํŠธ์— ์ ์šฉํ•ด๋ณด์ž! ์ž‘์€ ๊ฒƒ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด:

1. ๊ฐ„๋‹จํ•œ ์ฝ˜์†” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ๋‹ค๊ตญ์–ด ์ง€์› ์ถ”๊ฐ€
2. ๊ธฐ์กด ํ”„๋กœ์ ํŠธ์˜ ํ•˜๋“œ์ฝ”๋”ฉ๋œ ๋ฌธ์ž์—ด์„ ResourceBundle๋กœ ์ด๋™
3. ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ์–ธ์–ด ์„ ํƒ ๊ธฐ๋Šฅ ๊ตฌํ˜„
4. ๋ฒˆ์—ญ ๊ด€๋ฆฌ ๋„๊ตฌ ๋„์ž… ๊ฒ€ํ† 

์žฌ๋Šฅ๋„ท ๊ฐ™์€ ํ”Œ๋žซํผ์—์„œ ๊ธ€๋กœ๋ฒŒ ์„œ๋น„์Šค๋ฅผ ์ œ๊ณตํ•œ๋‹ค๋ฉด, ์ฒ˜์Œ๋ถ€ํ„ฐ ๊ตญ์ œํ™”๋ฅผ ๊ณ ๋ คํ•ด์„œ ์„ค๊ณ„ํ•˜๋Š” ๊ฒŒ ์ •๋ง ์ค‘์š”ํ•ด. ๋‚˜์ค‘์— ์ถ”๊ฐ€ํ•˜๋ ค๋ฉด ์—„์ฒญ๋‚œ ๋ฆฌํŒฉํ† ๋ง์ด ํ•„์š”ํ•˜๊ฑฐ๋“ ! ๐Ÿ’ช

ํ”„๋กœ๊ทธ๋ž˜๋ฐ์€ ๋‹จ์ˆœํžˆ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ, ์ „ ์„ธ๊ณ„ ์‚ฌ์šฉ์ž๋“ค์—๊ฒŒ ๊ฐ€์น˜๋ฅผ ์ „๋‹ฌํ•˜๋Š” ๊ฑฐ์•ผ. ๋‹ค๊ตญ์–ด ์ง€์›์€ ๊ทธ ์ฒซ๊ฑธ์Œ์ด์ง€! ๐ŸŒŸ

๊ถ๊ธˆํ•œ ์ ์ด ์žˆ๊ฑฐ๋‚˜ ๋” ์•Œ๊ณ  ์‹ถ์€ ๋‚ด์šฉ์ด ์žˆ๋‹ค๋ฉด ์–ธ์ œ๋“  ๋ฌผ์–ด๋ด. ํ•จ๊ป˜ ์„ฑ์žฅํ•˜๋Š” ๊ฐœ๋ฐœ์ž๊ฐ€ ๋˜์ž! ํ™”์ดํŒ…! ๐ŸŽ‰

๋Œ“๊ธ€ ์ž‘์„ฑ

์ด ๊ธ€์— ๋Œ€ํ•œ ์—ฌ๋Ÿฌ๋ถ„์˜ ์ƒ๊ฐ์„ ๋“ค๋ ค์ฃผ์„ธ์š”

๋Œ“๊ธ€ 0
๋Œ“๊ธ€์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ์ค‘์ž…๋‹ˆ๋‹ค.

์•„์ง ๋Œ“๊ธ€์ด ์—†์Šต๋‹ˆ๋‹ค.