Ver3.0 ๐ ๊ธ๋ก๋ฒ ์๋์ ํ์ ์คํฌ! ์์ฉํ๋ก๊ทธ๋๋ฐ์์ ๊ตญ์ ํ(i18n)์ ์ง์ญํ(l10n) ์๋ฒฝ ๊ตฌํ ๊ฐ์ด๋

๐ ๊ธ๋ก๋ฒ ์๋์ ํ์ ์คํฌ! ์์ฉํ๋ก๊ทธ๋๋ฐ์์ ๊ตญ์ ํ(i18n)์ ์ง์ญํ(l10n) ์๋ฒฝ ๊ตฌํ ๊ฐ์ด๋
์ ์ธ๊ณ ์ฌ์ฉ์๋ฅผ ์ฌ๋ก์ก๋ ๋ค๊ตญ์ด ์ ํ๋ฆฌ์ผ์ด์ ๊ฐ๋ฐ์ ๋ชจ๋ ๊ฒ
๐ฌ "์ฐ๋ฆฌ ์ฑ์ ํด์ธ์๋ ์ถ์ํ๊ณ ์ถ์๋ฐ, ์ด๋์๋ถํฐ ์์ํด์ผ ํ ๊น?"
์ด๋ฐ ๊ณ ๋ฏผ, ํ ๋ฒ์ฏค ํด๋ณด์
จ์ฃ ? ์์ฆ ๊ฐ์ ๊ธ๋ก๋ฒ ์๋์ ์ ํ๋ฆฌ์ผ์ด์
์ ๊ฐ๋ฐํ๋ค๋ฉด ๊ตญ์ ํ์ ์ง์ญํ๋ ์ ํ์ด ์๋ ํ์์์! ๐ ์ค๋์ ์ฌ๋ฌ๋ถ๊ณผ ํจ๊ป i18n(Internationalization)๊ณผ l10n(Localization)์ ์ธ๊ณ๋ก ๋ ๋๋ณผ ๊ฑฐ์์. ๋ณต์กํด ๋ณด์ด์ง๋ง ์ฐจ๊ทผ์ฐจ๊ทผ ๋ฐ๋ผ์ค์๋ฉด ์ด๋์ ๊ธ๋ก๋ฒ ์ฑ ๊ฐ๋ฐ์๊ฐ ๋์ด ์์ ๊ฑฐ๋๋๋ค!
๐ฏ i18n๊ณผ l10n, ๋๋์ฒด ๋ญ๊ฐ ๋ค๋ฅธ ๊ฑฐ์ผ?
๋จผ์ ์ฉ์ด๋ถํฐ ์ ๋ฆฌํ๊ณ ๊ฐ๊ฒ์! ์ด ๋ ๊ฐ๋ ์ด ํท๊ฐ๋ฆฌ๋ ๋ถ๋ค์ด ์ ๋ง ๋ง๊ฑฐ๋ ์. ๐
๐ค i18n (Internationalization, ๊ตญ์ ํ) "Internationalization"์ด๋ผ๋ ๋จ์ด๊ฐ ๋๋ฌด ๊ธธ์ด์ ์ฒซ ๊ธ์ 'I'์ ๋ง์ง๋ง ๊ธ์ 'N' ์ฌ์ด์ 18๊ฐ์ ๊ธ์๊ฐ ์๋ค๋ ์๋ฏธ๋ก i18n์ด๋ผ๊ณ ๋ถ๋ฆ ๋๋ค. ๊ตญ์ ํ๋ ์ ํ๋ฆฌ์ผ์ด์ ์ ๋ค์ํ ์ธ์ด์ ์ง์ญ์์ ์ฌ์ฉํ ์ ์๋๋ก ์ค๊ณํ๊ณ ๊ฐ๋ฐํ๋ ๊ณผ์ ์ด์์. ์ฝ๊ฒ ๋งํด, ๋์ค์ ์ด๋ค ์ธ์ด๋ก๋ ๋ฒ์ญํ ์ ์๋๋ก ๊ธฐ๋ฐ์ ๋ง๋๋ ๊ฑฐ์ฃ !
๐ l10n (Localization, ์ง์ญํ) ๋ง์ฐฌ๊ฐ์ง๋ก "Localization"์์ 'L'๊ณผ 'N' ์ฌ์ด์ 10๊ฐ์ ๊ธ์๊ฐ ์์ด์ l10n์ด๋ผ๊ณ ํด์. ์ง์ญํ๋ ํน์ ์ง์ญ์ด๋ ์ธ์ด์ ๋ง๊ฒ ์ ํ๋ฆฌ์ผ์ด์ ์ ์ค์ ๋ก ๋ฒ์ญํ๊ณ ์กฐ์ ํ๋ ๊ณผ์ ์ ๋๋ค. ๋ ์ง ํ์, ํตํ, ๋ฌธํ์ ์์๊น์ง ๊ณ ๋ คํ๋ ๊ฑฐ์์!
๐ค ๋น์ ๋ก ์ดํดํ๊ธฐ
๋ ๊ณ ๋ธ๋ก์ ์๊ฐํด๋ณด์ธ์! ๐งฑ
i18n์ ๋ค์ํ ๋ชจ์์ ์ง์ ์ง์ ์ ์๋๋ก ๋ฒ์ฉ ๋ ๊ณ ๋ธ๋ก ์ธํธ๋ฅผ ๋ง๋๋ ๊ฒ์ด๊ณ ,
l10n์ ๊ทธ ๋ธ๋ก์ผ๋ก ํ์ฅ, ์์ฅ, ์ด๊ธ๋ฃจ ๋ฑ ํน์ ์คํ์ผ์ ์ง์ ์ค์ ๋ก ์ง๋ ๊ฑฐ์์!
๊ตญ์ ํ๊ฐ ๋จผ์ ์ด๋ฃจ์ด์ ธ์ผ ์ง์ญํ๊ฐ ๊ฐ๋ฅํ๋ต๋๋ค. ๐ก
๐๏ธ ๊ตญ์ ํ(i18n) ๊ตฌํ์ ํต์ฌ ์์น
์, ์ด์ ๋ณธ๊ฒฉ์ ์ผ๋ก ๊ตญ์ ํ๋ฅผ ์ด๋ป๊ฒ ๊ตฌํํ๋์ง ์์๋ณผ๊น์? ํต์ฌ ์์น๋ถํฐ ์ฐจ๊ทผ์ฐจ๊ทผ ์ดํด๋ด ์๋ค! ๐
1๏ธโฃ ํ๋์ฝ๋ฉ๋ ๋ฌธ์์ด ๋ถ๋ฆฌํ๊ธฐ
๊ฐ์ฅ ๊ธฐ๋ณธ์ด๋ฉด์๋ ๊ฐ์ฅ ์ค์ํ ์์น์ด์์! ์ฝ๋ ์์ ์ง์ ๋ฌธ์์ด์ ๋ฐ์๋ฃ๋ ๊ฒ(ํ๋์ฝ๋ฉ)์ ์ ๋ ๊ธ๋ฌผ์
๋๋ค. ๐ฑ
// โ ๋์ ์์ - ํ๋์ฝ๋ฉ
function greetUser(name) {
return "์๋
ํ์ธ์, " + name + "๋!";
}
// โ
์ข์ ์์ - ์ธ๋ถ ๋ฆฌ์์ค ํ์ผ ์ฌ์ฉ
function greetUser(name) {
return i18n.t('greeting.welcome', { name: name });
}
์ ์์์ฒ๋ผ ๋ชจ๋ ์ฌ์ฉ์์๊ฒ ๋ณด์ด๋ ํ ์คํธ๋ ๋ณ๋์ ๋ฆฌ์์ค ํ์ผ๋ก ๋ถ๋ฆฌํด์ผ ํด์. ๊ทธ๋์ผ ๋์ค์ ๋ฒ์ญํ ๋ ์ฝ๋๋ฅผ ๊ฑด๋๋ฆฌ์ง ์๊ณ ๋ฆฌ์์ค ํ์ผ๋ง ์์ ํ๋ฉด ๋๊ฑฐ๋ ์! ๐ฏ
2๏ธโฃ ์ ๋์ฝ๋(Unicode) ์ฌ์ฉํ๊ธฐ
์ ์ธ๊ณ ๋ชจ๋ ๋ฌธ์๋ฅผ ํํํ ์ ์๋ ์ ๋์ฝ๋๋ฅผ ์ฌ์ฉํด์ผ ํด์. UTF-8 ์ธ์ฝ๋ฉ์ด ๊ฐ์ฅ ๋๋ฆฌ ์ฌ์ฉ๋๊ณ ์๋ต๋๋ค! ๐
// ํ์ผ ์ธ์ฝ๋ฉ์ UTF-8๋ก ์ค์
<meta charset="UTF-8">
// ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ UTF-8 ์ค์
CREATE DATABASE myapp CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
3๏ธโฃ ๋ก์ผ์ผ(Locale) ๊ธฐ๋ฐ ์ค๊ณ
๋ก์ผ์ผ์ ์ธ์ด์ ์ง์ญ์ ์กฐํฉํ ๊ฐ๋
์ด์์. ์๋ฅผ ๋ค์ด 'ko-KR'์ ํ๊ตญ์ ํ๊ตญ์ด, 'en-US'๋ ๋ฏธ๊ตญ์ ์์ด๋ฅผ ์๋ฏธํ์ฃ ! ๐บ๏ธ
| ๋ก์ผ์ผ ์ฝ๋ | ์๋ฏธ | ํน์ง |
|---|---|---|
| ko-KR | ํ๊ตญ์ด(๋ํ๋ฏผ๊ตญ) | ์ํ(โฉ), ๋ -์-์ผ ํ์ |
| en-US | ์์ด(๋ฏธ๊ตญ) | ๋ฌ๋ฌ($), ์/์ผ/๋ ํ์ |
| en-GB | ์์ด(์๊ตญ) | ํ์ด๋(ยฃ), ์ผ/์/๋ ํ์ |
| ja-JP | ์ผ๋ณธ์ด(์ผ๋ณธ) | ์(ยฅ), ๋ /์/์ผ ํ์ |
| zh-CN | ์ค๊ตญ์ด(์ค๊ตญ) | ์์(ยฅ), ๋ -์-์ผ ํ์ |
4๏ธโฃ ๋ฌธ์์ด ์ฐ๊ฒฐ ๋์ ํฌ๋งทํ
์ฌ์ฉ
์ธ์ด๋ง๋ค ๋ฌธ์ฅ ๊ตฌ์กฐ๊ฐ ๋ค๋ฅด๊ธฐ ๋๋ฌธ์ ๋จ์ํ ๋ฌธ์์ด์ ์ด์ด๋ถ์ด๋ฉด ์ ๋ผ์! ๐ต
// โ ๋์ ์์ - ๋ฌธ์์ด ์ฐ๊ฒฐ
message = "๋น์ ์ " + count + "๊ฐ์ ๋ฉ์์ง๊ฐ ์์ต๋๋ค.";
// โ
์ข์ ์์ - ํ๋ผ๋ฏธํฐ ํฌ๋งทํ
message = i18n.t('messages.count', { count: count });
// ๋ฆฌ์์ค ํ์ผ (ko.json)
{
"messages.count": "๋น์ ์ {count}๊ฐ์ ๋ฉ์์ง๊ฐ ์์ต๋๋ค."
}
// ๋ฆฌ์์ค ํ์ผ (en.json)
{
"messages.count": "You have {count} messages."
}
์์ด๋ "You have"๊ฐ ๋จผ์ ์ค์ง๋ง ํ๊ตญ์ด๋ "๋น์ ์"์ด ๋จผ์ ์ค์์์? ์ด๋ฐ ์ด์ ์ฐจ์ด๋ฅผ ํฌ๋งทํ ์ผ๋ก ํด๊ฒฐํ ์ ์์ด์! ๐ช
5๏ธโฃ ๋ณต์ํ ์ฒ๋ฆฌ (Pluralization)
์ธ์ด๋ง๋ค ๋ณต์ํ ๊ท์น์ด ์์ ํ ๋ฌ๋ผ์. ์์ด๋ ๋จ์/๋ณต์ 2๊ฐ์ง์ง๋ง, ๋ฌ์์์ด๋ 3๊ฐ์ง, ์๋์ด๋ 6๊ฐ์ง๋ ๋๋ต๋๋ค! ๐ฒ
// ๋ณต์ํ ์ฒ๋ฆฌ ์์
{
"items": {
"zero": "ํญ๋ชฉ์ด ์์ต๋๋ค",
"one": "1๊ฐ์ ํญ๋ชฉ",
"other": "{count}๊ฐ์ ํญ๋ชฉ"
}
}
// ์ฌ์ฉ
i18n.t('items', { count: 0 }); // "ํญ๋ชฉ์ด ์์ต๋๋ค"
i18n.t('items', { count: 1 }); // "1๊ฐ์ ํญ๋ชฉ"
i18n.t('items', { count: 5 }); // "5๊ฐ์ ํญ๋ชฉ"
๐ ๏ธ ์ฃผ์ ํ๋ก๊ทธ๋๋ฐ ์ธ์ด๋ณ i18n ๋ผ์ด๋ธ๋ฌ๋ฆฌ
๊ฐ ์ธ์ด์ ํ๋ ์์ํฌ๋ง๋ค ํ๋ฅญํ ๊ตญ์ ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ค์ด ์์ด์. ์ค๋ฌด์์ ๊ฐ์ฅ ๋ง์ด ์ฌ์ฉ๋๋ ๊ฒ๋ค์ ์๊ฐํ ๊ฒ์! ๐จ
๐ฑ JavaScript / TypeScript
i18next - ๊ฐ์ฅ ์ธ๊ธฐ ์๋ JavaScript i18n ํ๋ ์์ํฌ ๐
React, Vue, Angular ๋ฑ ๋ชจ๋ ์ฃผ์ ํ๋ ์์ํฌ์ ํธํ๋๋ฉฐ, ํ๋ฌ๊ทธ์ธ ์ํ๊ณ๊ฐ ๋งค์ฐ ํ๋ถํด์!
// i18next ์ค์น
npm install i18next react-i18next
// ์ด๊ธฐํ
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
i18n
.use(initReactI18next)
.init({
resources: {
ko: {
translation: {
"welcome": "ํ์ํฉ๋๋ค!",
"greeting": "์๋
ํ์ธ์, {{name}}๋!"
}
},
en: {
translation: {
"welcome": "Welcome!",
"greeting": "Hello, {{name}}!"
}
}
},
lng: "ko",
fallbackLng: "en",
interpolation: {
escapeValue: false
}
});
// React ์ปดํฌ๋ํธ์์ ์ฌ์ฉ
import { useTranslation } from 'react-i18next';
function MyComponent() {
const { t, i18n } = useTranslation();
const changeLanguage = (lng) => {
i18n.changeLanguage(lng);
};
return (
<div>
<h1>{t('welcome')}</h1>
<p>{t('greeting', { name: 'ํ๊ธธ๋' })}</p>
<button onClick={() => changeLanguage('en')}>English</button>
<button onClick={() => changeLanguage('ko')}>ํ๊ตญ์ด</button>
</div>
);
}
Vue I18n - Vue.js ์ ์ฉ ๊ตญ์ ํ ํ๋ฌ๊ทธ์ธ ๐ฏ
Vue ์ํ๊ณ์ ์๋ฒฝํ๊ฒ ํตํฉ๋์ด ์์ด์ Vue ๊ฐ๋ฐ์๋ผ๋ฉด ์ด๊ฒ ์ต๊ณ ์์!
// Vue I18n ์ค์น
npm install vue-i18n@9
// main.js ์ค์
import { createApp } from 'vue';
import { createI18n } from 'vue-i18n';
const messages = {
ko: {
message: {
hello: '์๋
ํ์ธ์',
welcome: '{name}๋, ํ์ํฉ๋๋ค!'
}
},
en: {
message: {
hello: 'Hello',
welcome: 'Welcome, {name}!'
}
}
};
const i18n = createI18n({
locale: 'ko',
fallbackLocale: 'en',
messages
});
const app = createApp(App);
app.use(i18n);
app.mount('#app');
// ์ปดํฌ๋ํธ์์ ์ฌ์ฉ
<template>
<div>
<p>{{ $t('message.hello') }}</p>
<p>{{ $t('message.welcome', { name: 'ํ๊ธธ๋' }) }}</p>
</div>
</template>
โ Java
ResourceBundle - Java ๋ด์ฅ ๊ตญ์ ํ API ๐ฆ
๋ณ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค์น ์์ด Java์์ ๊ธฐ๋ณธ ์ ๊ณตํ๋ ๊ฐ๋ ฅํ ๋๊ตฌ์์!
// messages_ko_KR.properties
greeting=์๋
ํ์ธ์, {0}๋!
farewell=์๋
ํ ๊ฐ์ธ์!
// messages_en_US.properties
greeting=Hello, {0}!
farewell=Goodbye!
// Java ์ฝ๋
import java.util.Locale;
import java.util.ResourceBundle;
import java.text.MessageFormat;
public class I18nExample {
public static void main(String[] args) {
// ํ๊ตญ์ด ๋ก์ผ์ผ
Locale koLocale = new Locale("ko", "KR");
ResourceBundle koBundle = ResourceBundle.getBundle("messages", koLocale);
String greeting = koBundle.getString("greeting");
String message = MessageFormat.format(greeting, "ํ๊ธธ๋");
System.out.println(message); // "์๋
ํ์ธ์, ํ๊ธธ๋๋!"
// ์์ด ๋ก์ผ์ผ
Locale enLocale = new Locale("en", "US");
ResourceBundle enBundle = ResourceBundle.getBundle("messages", enLocale);
greeting = enBundle.getString("greeting");
message = MessageFormat.format(greeting, "John");
System.out.println(message); // "Hello, John!"
}
}
Spring MessageSource - Spring Framework์ i18n ์ง์ ๐ฑ
Spring์ ์ฌ์ฉํ๋ค๋ฉด ์ด๊ฒ ๊ฐ์ฅ ์์ฐ์ค๋ฌ์ด ์ ํ์ด์์!
// application.properties
spring.messages.basename=messages
spring.messages.encoding=UTF-8
// messages_ko.properties
user.registered=์ฌ์ฉ์ {0}๋์ด ๋ฑ๋ก๋์์ต๋๋ค.
error.notfound=์์ฒญํ์ ๋ฆฌ์์ค๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค.
// messages_en.properties
user.registered=User {0} has been registered.
error.notfound=The requested resource was not found.
// Spring Controller
@RestController
public class UserController {
@Autowired
private MessageSource messageSource;
@PostMapping("/users")
public ResponseEntity<String> registerUser(
@RequestBody User user,
@RequestHeader(value = "Accept-Language", defaultValue = "ko") String lang) {
Locale locale = Locale.forLanguageTag(lang);
String message = messageSource.getMessage(
"user.registered",
new Object[]{user.getName()},
locale
);
return ResponseEntity.ok(message);
}
}
๐ Python
gettext - Python ํ์ค ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๐
GNU gettext๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ํ Python์ ๊ณต์ i18n ์๋ฃจ์
์ด์์!
# ์ค์น (ํ์ค ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ผ ๋ณ๋ ์ค์น ๋ถํ์)
import gettext
# ๋ฒ์ญ ํ์ผ ์ค์
ko = gettext.translation('messages', localedir='locales', languages=['ko'])
ko.install()
# ์ฌ์ฉ
_ = ko.gettext
print(_('Hello, World!')) # "์๋
ํ์ธ์, ์ธ๊ณ!"
# ํฌ๋งทํ
์ฌ์ฉ
name = "ํ๊ธธ๋"
print(_('Welcome, {name}!').format(name=name))
# .po ํ์ผ ์์ฑ (messages.pot ํ
ํ๋ฆฟ)
# msgid "Hello, World!"
# msgstr "์๋
ํ์ธ์, ์ธ๊ณ!"
#
# msgid "Welcome, {name}!"
# msgstr "{name}๋, ํ์ํฉ๋๋ค!"
Flask-Babel / Django i18n - ์น ํ๋ ์์ํฌ ํตํฉ ๐
Flask๋ Django๋ฅผ ์ฌ์ฉํ๋ค๋ฉด ๊ฐ๊ฐ์ i18n ํ์ฅ์ ์ฌ์ฉํ๋ ๊ฒ ํธํด์!
# Flask-Babel ์์
from flask import Flask, request
from flask_babel import Babel, gettext
app = Flask(__name__)
babel = Babel(app)
@babel.localeselector
def get_locale():
return request.accept_languages.best_match(['ko', 'en'])
@app.route('/')
def index():
return gettext('Hello, World!')
# Django ์์ (settings.py)
LANGUAGE_CODE = 'ko-kr'
USE_I18N = True
USE_L10N = True
LANGUAGES = [
('ko', 'Korean'),
('en', 'English'),
]
LOCALE_PATHS = [
os.path.join(BASE_DIR, 'locale'),
]
# Django ํ
ํ๋ฆฟ์์ ์ฌ์ฉ
{% load i18n %}
<h1>{% trans "Welcome" %}</h1>
<p>{% blocktrans with name=user.name %}Hello, {{ name }}!{% endblocktrans %}</p>
๐ Ruby
Ruby I18n - Ruby on Rails ๋ด์ฅ gem ๐
Rails์ ๊ธฐ๋ณธ ํฌํจ๋์ด ์์ด์ ๋ณ๋ ์ค์ ์์ด ๋ฐ๋ก ์ฌ์ฉ ๊ฐ๋ฅํด์!
# config/locales/ko.yml
ko:
hello: "์๋
ํ์ธ์"
greeting: "์๋
ํ์ธ์, %{name}๋!"
messages:
success: "์ฑ๊ณต์ ์ผ๋ก ์ฒ๋ฆฌ๋์์ต๋๋ค."
# config/locales/en.yml
en:
hello: "Hello"
greeting: "Hello, %{name}!"
messages:
success: "Successfully processed."
# Ruby ์ฝ๋์์ ์ฌ์ฉ
I18n.locale = :ko
I18n.t('hello') # "์๋
ํ์ธ์"
I18n.t('greeting', name: 'ํ๊ธธ๋') # "์๋
ํ์ธ์, ํ๊ธธ๋๋!"
# Rails Controller
class UsersController < ApplicationController
before_action :set_locale
def set_locale
I18n.locale = params[:locale] || I18n.default_locale
end
def create
if @user.save
flash[:notice] = t('messages.success')
redirect_to @user
end
end
end
๐ ์ง์ญํ(l10n) ๊ตฌํ์ ํต์ฌ ์์
๊ตญ์ ํ๋ก ๊ธฐ๋ฐ์ ๋ค์ก๋ค๋ฉด, ์ด์ ๊ฐ ์ง์ญ์ ๋ง๊ฒ ์ธ๋ฐํ๊ฒ ์กฐ์ ํ๋ ์ง์ญํ ์์ ์ด ํ์ํด์! ๋จ์ํ ๋ฒ์ญ๋ง ํ๋ ๊ฒ ์๋๋ผ ๋ฌธํ์ ์ฐจ์ด๊น์ง ๊ณ ๋ คํด์ผ ํ๋ต๋๋ค. ๐จ
๐ ๋ ์ง์ ์๊ฐ ํ์
โ ๏ธ ์ฃผ์! ๋ ์ง ํ์์ ๋๋ผ๋ง๋ค ์์ ํ ๋ฌ๋ผ์!
ํ๊ตญ: 2024๋
1์ 15์ผ (๋
-์-์ผ)
๋ฏธ๊ตญ: January 15, 2024 (์ ์ผ, ๋
)
์๊ตญ: 15 January 2024 (์ผ ์ ๋
)
์ด๊ฑธ ํ๋์ฝ๋ฉํ๋ฉด ํฐ์ผ๋์! ๐ฑ
// JavaScript - Intl.DateTimeFormat ์ฌ์ฉ
const date = new Date('2024-01-15');
// ํ๊ตญ์ด ํ์
const koFormatter = new Intl.DateTimeFormat('ko-KR', {
year: 'numeric',
month: 'long',
day: 'numeric'
});
console.log(koFormatter.format(date)); // "2024๋
1์ 15์ผ"
// ๋ฏธ๊ตญ ์์ด ํ์
const usFormatter = new Intl.DateTimeFormat('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
});
console.log(usFormatter.format(date)); // "January 15, 2024"
// ์๊ฐ ํ์๋ ๋ค๋ฅด๊ฒ!
const timeFormatter = new Intl.DateTimeFormat('ko-KR', {
hour: '2-digit',
minute: '2-digit',
hour12: false
});
console.log(timeFormatter.format(date)); // "00:00" (24์๊ฐ ํ์)
const usTimeFormatter = new Intl.DateTimeFormat('en-US', {
hour: '2-digit',
minute: '2-digit',
hour12: true
});
console.log(usTimeFormatter.format(date)); // "12:00 AM" (12์๊ฐ ํ์)
// Java - DateTimeFormatter ์ฌ์ฉ
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.Locale;
LocalDate date = LocalDate.of(2024, 1, 15);
// ํ๊ตญ์ด ํ์
DateTimeFormatter koFormatter = DateTimeFormatter
.ofLocalizedDate(FormatStyle.LONG)
.withLocale(Locale.KOREA);
System.out.println(date.format(koFormatter)); // "2024๋
1์ 15์ผ"
// ๋ฏธ๊ตญ ์์ด ํ์
DateTimeFormatter usFormatter = DateTimeFormatter
.ofLocalizedDate(FormatStyle.LONG)
.withLocale(Locale.US);
System.out.println(date.format(usFormatter)); // "January 15, 2024"
๐ฐ ํตํ ๋ฐ ์ซ์ ํ์
๐ก ์์๋์ธ์!
์ซ์ ํ๊ธฐ๋ฒ๋ ๋๋ผ๋ง๋ค ๋ฌ๋ผ์!
ํ๊ตญ/๋ฏธ๊ตญ: 1,234,567.89 (์ผํ๋ก ์ฒ ๋จ์ ๊ตฌ๋ถ, ์ ์ผ๋ก ์์์ )
๋
์ผ/ํ๋์ค: 1.234.567,89 (์ ์ผ๋ก ์ฒ ๋จ์ ๊ตฌ๋ถ, ์ผํ๋ก ์์์ )
ํตํ ๊ธฐํธ ์์น๋ ๋ค๋ฅด๋ต๋๋ค! ๐ธ
// JavaScript - Intl.NumberFormat ์ฌ์ฉ
const amount = 1234567.89;
// ํ๊ตญ ์ํ
const krwFormatter = new Intl.NumberFormat('ko-KR', {
style: 'currency',
currency: 'KRW'
});
console.log(krwFormatter.format(amount)); // "โฉ1,234,568"
// ๋ฏธ๊ตญ ๋ฌ๋ฌ
const usdFormatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD'
});
console.log(usdFormatter.format(amount)); // "$1,234,567.89"
// ์ ๋ก (๋
์ผ ํ์)
const eurFormatter = new Intl.NumberFormat('de-DE', {
style: 'currency',
currency: 'EUR'
});
console.log(eurFormatter.format(amount)); // "1.234.567,89 โฌ"
// ํผ์ผํธ ํ์
const percentFormatter = new Intl.NumberFormat('ko-KR', {
style: 'percent',
minimumFractionDigits: 2
});
console.log(percentFormatter.format(0.1234)); // "12.34%"
// Python - locale ๋ชจ๋ ์ฌ์ฉ
import locale
# ํ๊ตญ ๋ก์ผ์ผ ์ค์
locale.setlocale(locale.LC_ALL, 'ko_KR.UTF-8')
amount = 1234567.89
print(locale.currency(amount, grouping=True)) # "โฉ1,234,568"
# ๋ฏธ๊ตญ ๋ก์ผ์ผ ์ค์
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
print(locale.currency(amount, grouping=True)) # "$1,234,567.89"
# ์ซ์ ํ์
print(locale.format_string("%d", 1234567, grouping=True)) # "1,234,567"
๐ ๋จ์ ์์คํ
๋ฏธํฐ๋ฒ vs ์ผ๋ํ์ด๋๋ฒ โ๏ธ
๋๋ถ๋ถ์ ๋๋ผ๋ ๋ฏธํฐ๋ฒ์ ์ฌ์ฉํ์ง๋ง, ๋ฏธ๊ตญ์ ์ผ๋ํ์ด๋๋ฒ์ ์ฌ์ฉํด์!
- ๊ธธ์ด: km โ miles
- ๋ฌด๊ฒ: kg โ pounds
- ์จ๋: ยฐC โ ยฐF
์ด๊ฒ๋ ์๋ ๋ณํ์ด ํ์ํ๋ต๋๋ค!
// ๋จ์ ๋ณํ ์์
function convertTemperature(value, fromUnit, toUnit) {
if (fromUnit === 'C' && toUnit === 'F') {
return (value * 9/5) + 32;
} else if (fromUnit === 'F' && toUnit === 'C') {
return (value - 32) * 5/9;
}
return value;
}
// ๋ก์ผ์ผ์ ๋ฐ๋ฅธ ์๋ ๋ณํ
function displayTemperature(celsius, locale) {
if (locale === 'en-US') {
const fahrenheit = convertTemperature(celsius, 'C', 'F');
return `${fahrenheit.toFixed(1)}ยฐF`;
}
return `${celsius.toFixed(1)}ยฐC`;
}
console.log(displayTemperature(25, 'ko-KR')); // "25.0ยฐC"
console.log(displayTemperature(25, 'en-US')); // "77.0ยฐF"
๐จ ๋ฌธํ์ ์์ ๊ณ ๋ ค
๐จ ๋ฌธํ์ ๋ฏผ๊ฐ์ฑ ์ฃผ์!
์์, ์ด๋ฏธ์ง, ์์ด์ฝ์ ์๋ฏธ๊ฐ ๋ฌธํ๋ง๋ค ๋ค๋ฅผ ์ ์์ด์:
๐ด ๋นจ๊ฐ์: ํ๊ตญ/์ค๊ตญ์์๋ ํ์ด, ์์์์๋ ์ํ
๐ค ์๋์: ๋๋ผ๋ง๋ค ์๋ฏธ๊ฐ ์์ ํ ๋ค๋ฆ
๐ฆ ๋๋ฌผ ์์ง: ์ฌ๋นผ๋ฏธ๋ ์์์์ ์งํ, ์ผ๋ถ ์์์์์๋ ๋ถ๊ธธ
์ด๋ฐ ์์๋ค๋ ์ง์ญํ ๊ณผ์ ์์ ์กฐ์ ํด์ผ ํด์!
| ์์ | ํ๊ตญ/๋์์์ | ์์ | ์ค๋ |
|---|---|---|---|
| ํ ์คํธ ๋ฐฉํฅ | ์ผ์ชฝโ์ค๋ฅธ์ชฝ | ์ผ์ชฝโ์ค๋ฅธ์ชฝ | ์ค๋ฅธ์ชฝโ์ผ์ชฝ (RTL) |
| ์ด๋ฆ ์์ | ์ฑ + ์ด๋ฆ | ์ด๋ฆ + ์ฑ | ๋ณต์กํ ๊ตฌ์กฐ |
| ์ฃผ์ ํ์ | ํฐ ๋จ์โ์์ ๋จ์ | ์์ ๋จ์โํฐ ๋จ์ | ๋ค์ํจ |
| ์ ํ๋ฒํธ | 010-1234-5678 | (123) 456-7890 | +971 50 123 4567 |
๐ RTL (Right-to-Left) ์ง์
๐ ์๋์ด, ํ๋ธ๋ฆฌ์ด ๋ฑ์ ์ค๋ฅธ์ชฝ์์ ์ผ์ชฝ์ผ๋ก ์ฝ์ด์! UI ๋ ์ด์์ ์์ฒด๋ฅผ ๊ฑฐ์ธ์ฒ๋ผ ๋ค์ง์ด์ผ ํ๋ ๊ฒฝ์ฐ๊ฐ ๋ง๋ต๋๋ค. CSS์ `dir` ์์ฑ๊ณผ ๋ ผ๋ฆฌ์ ์์ฑ์ ํ์ฉํ์ธ์!
/* CSS์์ RTL ์ง์ */
/* ๋ฌผ๋ฆฌ์ ์์ฑ ๋์ ๋
ผ๋ฆฌ์ ์์ฑ ์ฌ์ฉ */
/* โ ๋์ ์์ */
.button {
margin-left: 10px;
padding-right: 20px;
}
/* โ
์ข์ ์์ */
.button {
margin-inline-start: 10px; /* LTR์์๋ left, RTL์์๋ right */
padding-inline-end: 20px; /* LTR์์๋ right, RTL์์๋ left */
}
/* HTML์์ ๋ฐฉํฅ ์ง์ */
<html dir="rtl" lang="ar">
<!-- ์๋์ด ์ฝํ
์ธ -->
</html>
/* JavaScript๋ก ๋์ ๋ณ๊ฒฝ */
function setLanguage(lang) {
const isRTL = ['ar', 'he', 'fa'].includes(lang);
document.documentElement.dir = isRTL ? 'rtl' : 'ltr';
document.documentElement.lang = lang;
}
๐ง ์ค์ ๊ตฌํ ์ํฌํ๋ก์ฐ
์ด๋ก ์ ์ถฉ๋ถํ ๋ฐฐ์ ์ผ๋, ์ด์ ์ค์ ๋ก ์ด๋ป๊ฒ ํ๋ก์ ํธ์ ์ ์ฉํ๋์ง ๋จ๊ณ๋ณ๋ก ์์๋ณผ๊น์? ๐
Step 1: ํ๋ก์ ํธ ๊ตฌ์กฐ ์ค๊ณ ๐
๋ฒ์ญ ํ์ผ์ ์ฒด๊ณ์ ์ผ๋ก ๊ด๋ฆฌํ ์ ์๋ ๊ตฌ์กฐ๋ฅผ ๋จผ์ ๋ง๋ค์ด์!
project/
โโโ src/
โ โโโ locales/ # ๋ฒ์ญ ํ์ผ ๋๋ ํ ๋ฆฌ
โ โ โโโ ko/
โ โ โ โโโ common.json # ๊ณตํต ๋ฌธ๊ตฌ
โ โ โ โโโ auth.json # ์ธ์ฆ ๊ด๋ จ
โ โ โ โโโ product.json # ์ํ ๊ด๋ จ
โ โ โ โโโ error.json # ์๋ฌ ๋ฉ์์ง
โ โ โโโ en/
โ โ โ โโโ common.json
โ โ โ โโโ auth.json
โ โ โ โโโ product.json
โ โ โ โโโ error.json
โ โ โโโ ja/
โ โ โโโ ...
โ โโโ i18n/
โ โ โโโ config.js # i18n ์ค์
โ โ โโโ index.js # i18n ์ด๊ธฐํ
โ โโโ components/
โโโ package.json
Step 2: ๋ฒ์ญ ํค ๋ค์ด๋ฐ ์ปจ๋ฒค์
์ ํ๊ธฐ ๐ท๏ธ
์ผ๊ด๋ ๋ค์ด๋ฐ ๊ท์น์ด ์์ด์ผ ๋์ค์ ๊ด๋ฆฌ๊ฐ ์ฌ์์!
// ์ถ์ฒ ๋ค์ด๋ฐ ์ปจ๋ฒค์
{
// ๊ธฐ๋ฅ.ํ๋ฉด.์์.์ํ ํ์
"auth.login.button.submit": "๋ก๊ทธ์ธ",
"auth.login.input.email.placeholder": "์ด๋ฉ์ผ์ ์
๋ ฅํ์ธ์",
"auth.login.error.invalid": "์ด๋ฉ์ผ ๋๋ ๋น๋ฐ๋ฒํธ๊ฐ ์ฌ๋ฐ๋ฅด์ง ์์ต๋๋ค",
// ๊ณตํต ์์๋ common ๋ค์์คํ์ด์ค
"common.button.save": "์ ์ฅ",
"common.button.cancel": "์ทจ์",
"common.button.delete": "์ญ์ ",
// ์๋ฌ ๋ฉ์์ง๋ error ๋ค์์คํ์ด์ค
"error.network.timeout": "๋คํธ์ํฌ ์ฐ๊ฒฐ ์๊ฐ์ด ์ด๊ณผ๋์์ต๋๋ค",
"error.server.internal": "์๋ฒ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค",
// ๋ณต์ํ์ ๋ช
์์ ์ผ๋ก ํ์
"product.count.zero": "์ํ์ด ์์ต๋๋ค",
"product.count.one": "1๊ฐ์ ์ํ",
"product.count.other": "{{count}}๊ฐ์ ์ํ"
}
Step 3: ๋ฒ์ญ ํ์ผ ์์ฑ โ๏ธ
JSON ํ์์ผ๋ก ๊น๋ํ๊ฒ ์ ๋ฆฌํด์!
// locales/ko/common.json
{
"app": {
"name": "์ฐ๋ฆฌ ์ฑ",
"description": "์ต๊ณ ์ ์๋น์ค๋ฅผ ์ ๊ณตํฉ๋๋ค"
},
"navigation": {
"home": "ํ",
"products": "์ํ",
"about": "์๊ฐ",
"contact": "๋ฌธ์"
},
"button": {
"save": "์ ์ฅ",
"cancel": "์ทจ์",
"delete": "์ญ์ ",
"edit": "์์ ",
"confirm": "ํ์ธ"
},
"message": {
"success": "์ฑ๊ณต์ ์ผ๋ก ์ฒ๋ฆฌ๋์์ต๋๋ค",
"error": "์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค",
"loading": "๋ก๋ฉ ์ค...",
"noData": "๋ฐ์ดํฐ๊ฐ ์์ต๋๋ค"
}
}
// locales/en/common.json
{
"app": {
"name": "Our App",
"description": "Providing the best service"
},
"navigation": {
"home": "Home",
"products": "Products",
"about": "About",
"contact": "Contact"
},
"button": {
"save": "Save",
"cancel": "Cancel",
"delete": "Delete",
"edit": "Edit",
"confirm": "Confirm"
},
"message": {
"success": "Successfully processed",
"error": "An error occurred",
"loading": "Loading...",
"noData": "No data available"
}
}
Step 4: ๋ก์ผ์ผ ๊ฐ์ง ๋ฐ ์ค์ ๐
์ฌ์ฉ์์ ์ธ์ด๋ฅผ ์๋์ผ๋ก ๊ฐ์งํ๊ณ ์ ์ ํ ์ธ์ด๋ฅผ ์ ๊ณตํด์!
// ๋ธ๋ผ์ฐ์ ์ธ์ด ๊ฐ์ง
function detectUserLocale() {
// 1. URL ํ๋ผ๋ฏธํฐ ํ์ธ
const urlParams = new URLSearchParams(window.location.search);
const urlLocale = urlParams.get('lang');
if (urlLocale) return urlLocale;
// 2. ๋ก์ปฌ ์คํ ๋ฆฌ์ง ํ์ธ (์ฌ์ฉ์๊ฐ ์ด์ ์ ์ ํํ ์ธ์ด)
const savedLocale = localStorage.getItem('userLocale');
if (savedLocale) return savedLocale;
// 3. ๋ธ๋ผ์ฐ์ ์ค์ ํ์ธ
const browserLocale = navigator.language || navigator.userLanguage;
// 4. ์ง์ํ๋ ์ธ์ด ๋ชฉ๋ก๊ณผ ๋งค์นญ
const supportedLocales = ['ko', 'en', 'ja', 'zh'];
const locale = browserLocale.split('-')[0]; // 'ko-KR' -> 'ko'
return supportedLocales.includes(locale) ? locale : 'en'; // ๊ธฐ๋ณธ๊ฐ: ์์ด
}
// ๋ก์ผ์ผ ๋ณ๊ฒฝ ํจ์
function changeLocale(newLocale) {
// 1. i18n ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ธ์ด ๋ณ๊ฒฝ
i18n.changeLanguage(newLocale);
// 2. ๋ก์ปฌ ์คํ ๋ฆฌ์ง์ ์ ์ฅ
localStorage.setItem('userLocale', newLocale);
// 3. HTML lang ์์ฑ ๋ณ๊ฒฝ
document.documentElement.lang = newLocale;
// 4. RTL ์ง์
const rtlLanguages = ['ar', 'he', 'fa'];
document.documentElement.dir = rtlLanguages.includes(newLocale) ? 'rtl' : 'ltr';
// 5. ํ์ด์ง ์๋ก๊ณ ์นจ (ํ์ํ ๊ฒฝ์ฐ)
// window.location.reload();
}
// ์ด๊ธฐํ
const initialLocale = detectUserLocale();
changeLocale(initialLocale);
Step 5: ๋ฒ์ญ ๋๋ฝ ์ฒ๋ฆฌ โ ๏ธ
๋ฒ์ญ์ด ์๋ ๊ฒฝ์ฐ๋ฅผ ๋๋นํ ํด๋ฐฑ(fallback) ์ ๋ต์ด ํ์ํด์!
// i18next ์ค์ ์์
i18n.init({
fallbackLng: 'en', // ๊ธฐ๋ณธ ์ธ์ด
fallbackNS: 'common', // ๊ธฐ๋ณธ ๋ค์์คํ์ด์ค
// ๋ฒ์ญ ๋๋ฝ ์ ์ฒ๋ฆฌ
saveMissing: true, // ๋๋ฝ๋ ํค ์ ์ฅ
missingKeyHandler: (lng, ns, key, fallbackValue) => {
console.warn(`Missing translation: [${lng}] ${ns}:${key}`);
// ๊ฐ๋ฐ ํ๊ฒฝ์์ ๋๋ฝ๋ ๋ฒ์ญ์ ์ถ์ ํ๊ธฐ ์ํด ๋ก๊น
if (process.env.NODE_ENV === 'development') {
// ๋๋ฝ๋ ํค๋ฅผ ํ์ผ๋ก ์ ์ฅํ๊ฑฐ๋ API๋ก ์ ์ก
reportMissingTranslation(lng, ns, key);
}
},
// ํค๋ฅผ ๊ทธ๋๋ก ํ์ํ์ง ์๊ณ ๋ ์นํ์ ์ธ ๋ฉ์์ง ํ์
parseMissingKeyHandler: (key) => {
return `[๋ฒ์ญ ํ์: ${key}]`;
}
});
// ๋ฒ์ญ ๋๋ฝ ๋ฆฌํฌํ
ํจ์
function reportMissingTranslation(language, namespace, key) {
// ๊ฐ๋ฐ ์๋ฒ๋ ๋ก๊น
์์คํ
์ผ๋ก ์ ์ก
fetch('/api/missing-translations', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ language, namespace, key, timestamp: new Date() })
});
}
Step 6: ๋ฒ์ญ ํ์ง ๊ด๋ฆฌ โ
๋ฒ์ญ์ ์ผ๊ด์ฑ๊ณผ ํ์ง์ ์ ์งํ๋ ๊ฒ์ด ์ค์ํด์!
// ๋ฒ์ญ ๊ฒ์ฆ ์คํฌ๋ฆฝํธ (Node.js)
const fs = require('fs');
const path = require('path');
function validateTranslations() {
const localesDir = './src/locales';
const languages = ['ko', 'en', 'ja'];
const namespaces = ['common', 'auth', 'product'];
// ๊ธฐ์ค ์ธ์ด (๋ณดํต ๊ฐ๋ฐ ์ธ์ด)
const baseLanguage = 'ko';
const issues = [];
namespaces.forEach(namespace => {
// ๊ธฐ์ค ์ธ์ด ํ์ผ ๋ก๋
const basePath = path.join(localesDir, baseLanguage, `${namespace}.json`);
const baseTranslations = JSON.parse(fs.readFileSync(basePath, 'utf8'));
const baseKeys = getAllKeys(baseTranslations);
// ๋ค๋ฅธ ์ธ์ด๋ค๊ณผ ๋น๊ต
languages.forEach(lang => {
if (lang === baseLanguage) return;
const langPath = path.join(localesDir, lang, `${namespace}.json`);
if (!fs.existsSync(langPath)) {
issues.push(`โ Missing file: ${langPath}`);
return;
}
const langTranslations = JSON.parse(fs.readFileSync(langPath, 'utf8'));
const langKeys = getAllKeys(langTranslations);
// ๋๋ฝ๋ ํค ์ฐพ๊ธฐ
const missingKeys = baseKeys.filter(key => !langKeys.includes(key));
if (missingKeys.length > 0) {
issues.push(`โ ๏ธ [${lang}/${namespace}] Missing keys: ${missingKeys.join(', ')}`);
}
// ์ถ๊ฐ๋ ํค ์ฐพ๊ธฐ (๊ธฐ์ค ์ธ์ด์ ์๋ ํค)
const extraKeys = langKeys.filter(key => !baseKeys.includes(key));
if (extraKeys.length > 0) {
issues.push(`โน๏ธ [${lang}/${namespace}] Extra keys: ${extraKeys.join(', ')}`);
}
});
});
// ๊ฒฐ๊ณผ ์ถ๋ ฅ
if (issues.length === 0) {
console.log('โ
All translations are in sync!');
} else {
console.log('๐ Translation issues found:\n');
issues.forEach(issue => console.log(issue));
process.exit(1); // CI/CD์์ ์คํจ ์ฒ๋ฆฌ
}
}
// ์ค์ฒฉ๋ ๊ฐ์ฒด์ ๋ชจ๋ ํค๋ฅผ ํํํ
function getAllKeys(obj, prefix = '') {
let keys = [];
for (let key in obj) {
const fullKey = prefix ? `${prefix}.${key}` : key;
if (typeof obj[key] === 'object' && obj[key] !== null) {
keys = keys.concat(getAllKeys(obj[key], fullKey));
} else {
keys.push(fullKey);
}
}
return keys;
}
validateTranslations();
๐ฏ ์ค์ ํ๋ก์ ํธ ์์ : React ๋ค๊ตญ์ด ์ผํ๋ชฐ
์ด๋ก ๋ง ๋ฐฐ์ฐ๋ฉด ์ฌ๋ฏธ์์ฃ ? ์ค์ ๋ก ๋์ํ๋ ์์ ํ ์์ ๋ฅผ ๋ง๋ค์ด๋ณผ๊ฒ์! ๐
๐ก ํ๋ก์ ํธ ๊ฐ์ ๊ฐ๋จํ ์ผํ๋ชฐ ์ ํ๋ฆฌ์ผ์ด์ ์ ๋ง๋ค๋ฉด์ i18n/l10n์ ์ ์ฉํด๋ณผ ๊ฑฐ์์. ํ๊ตญ์ด, ์์ด, ์ผ๋ณธ์ด 3๊ฐ ์ธ์ด๋ฅผ ์ง์ํ๊ณ , ํตํ์ ๋ ์ง ํ์๋ ์๋์ผ๋ก ๋ณํ๋๋ ๋ฉ์ง ์ฑ์ ๋ง๋ค์ด๋ด ์๋ค! ๐
// 1. ํจํค์ง ์ค์น
npm install react i18next react-i18next
// 2. i18n ์ค์ ํ์ผ (src/i18n/config.js)
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
// ๋ฒ์ญ ๋ฆฌ์์ค
const resources = {
ko: {
translation: {
nav: {
home: 'ํ',
products: '์ํ',
cart: '์ฅ๋ฐ๊ตฌ๋',
account: '๋ด ๊ณ์ '
},
product: {
title: '์ํ ๋ชฉ๋ก',
price: '๊ฐ๊ฒฉ',
addToCart: '์ฅ๋ฐ๊ตฌ๋์ ๋ด๊ธฐ',
inStock: '์ฌ๊ณ ์์',
outOfStock: 'ํ์ ',
description: '์ํ ์ค๋ช
'
},
cart: {
title: '์ฅ๋ฐ๊ตฌ๋',
empty: '์ฅ๋ฐ๊ตฌ๋๊ฐ ๋น์ด์์ต๋๋ค',
total: '์ด ๊ธ์ก',
checkout: '๊ฒฐ์ ํ๊ธฐ',
itemCount_zero: '์ํ์ด ์์ต๋๋ค',
itemCount_one: '1๊ฐ์ ์ํ',
itemCount_other: '{{count}}๊ฐ์ ์ํ'
},
common: {
loading: '๋ก๋ฉ ์ค...',
error: '์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค',
save: '์ ์ฅ',
cancel: '์ทจ์',
confirm: 'ํ์ธ'
}
}
},
en: {
translation: {
nav: {
home: 'Home',
products: 'Products',
cart: 'Cart',
account: 'My Account'
},
product: {
title: 'Product List',
price: 'Price',
addToCart: 'Add to Cart',
inStock: 'In Stock',
outOfStock: 'Out of Stock',
description: 'Description'
},
cart: {
title: 'Shopping Cart',
empty: 'Your cart is empty',
total: 'Total',
checkout: 'Checkout',
itemCount_zero: 'No items',
itemCount_one: '1 item',
itemCount_other: '{{count}} items'
},
common: {
loading: 'Loading...',
error: 'An error occurred',
save: 'Save',
cancel: 'Cancel',
confirm: 'Confirm'
}
}
},
ja: {
translation: {
nav: {
home: 'ใใผใ ',
products: 'ๅๅ',
cart: 'ใซใผใ',
account: 'ใใคใขใซใฆใณใ'
},
product: {
title: 'ๅๅไธ่ฆง',
price: 'ไพกๆ ผ',
addToCart: 'ใซใผใใซๅ
ฅใใ',
inStock: 'ๅจๅบซใใ',
outOfStock: 'ๅจๅบซๅใ',
description: 'ๅๅ่ชฌๆ'
},
cart: {
title: 'ใทใงใใใณใฐใซใผใ',
empty: 'ใซใผใใฏ็ฉบใงใ',
total: 'ๅ่จ',
checkout: 'ใใงใใฏใขใฆใ',
itemCount_zero: 'ๅๅใชใ',
itemCount_one: '1ๅใฎๅๅ',
itemCount_other: '{{count}}ๅใฎๅๅ'
},
common: {
loading: '่ชญใฟ่พผใฟไธญ...',
error: 'ใจใฉใผใ็บ็ใใพใใ',
save: 'ไฟๅญ',
cancel: 'ใญใฃใณใปใซ',
confirm: '็ขบ่ช'
}
}
}
};
i18n
.use(LanguageDetector)
.use(initReactI18next)
.init({
resources,
fallbackLng: 'en',
interpolation: {
escapeValue: false
}
});
export default i18n;
// 3. ์ธ์ด ์ ํ ์ปดํฌ๋ํธ (src/components/LanguageSelector.jsx)
import React from 'react';
import { useTranslation } from 'react-i18next';
const LanguageSelector = () => {
const { i18n } = useTranslation();
const languages = [
{ code: 'ko', name: 'ํ๊ตญ์ด', flag: '๐ฐ๐ท' },
{ code: 'en', name: 'English', flag: '๐บ๐ธ' },
{ code: 'ja', name: 'ๆฅๆฌ่ช', flag: '๐ฏ๐ต' }
];
const changeLanguage = (lng) => {
i18n.changeLanguage(lng);
localStorage.setItem('userLanguage', lng);
};
return (
<div style={{ display: 'flex', gap: '10px' }}>
{languages.map(lang => (
<button
key={lang.code}
onClick={() => changeLanguage(lang.code)}
style={{
padding: '8px 16px',
border: i18n.language === lang.code ? '2px solid #4a5568' : '1px solid #ccc',
borderRadius: '8px',
background: i18n.language === lang.code ? '#e3f2fd' : 'white',
cursor: 'pointer',
fontWeight: i18n.language === lang.code ? 'bold' : 'normal'
}}
>
{lang.flag} {lang.name}
</button>
))}
</div>
);
};
export default LanguageSelector;
// 4. ์ํ ์นด๋ ์ปดํฌ๋ํธ (src/components/ProductCard.jsx)
import React from 'react';
import { useTranslation } from 'react-i18next';
const ProductCard = ({ product }) => {
const { t, i18n } = useTranslation();
// ๋ก์ผ์ผ์ ๋ง๋ ํตํ ํฌ๋งท
const formatPrice = (price) => {
const currencyMap = {
ko: { currency: 'KRW', locale: 'ko-KR' },
en: { currency: 'USD', locale: 'en-US' },
ja: { currency: 'JPY', locale: 'ja-JP' }
};
const { currency, locale } = currencyMap[i18n.language] || currencyMap.en;
return new Intl.NumberFormat(locale, {
style: 'currency',
currency: currency
}).format(price);
};
// ๋ก์ผ์ผ์ ๋ง๋ ๋ ์ง ํฌ๋งท
const formatDate = (date) => {
return new Intl.DateTimeFormat(i18n.language, {
year: 'numeric',
month: 'long',
day: 'numeric'
}).format(new Date(date));
};
return (
<div style={{
border: '1px solid #e0e0e0',
borderRadius: '12px',
padding: '20px',
margin: '10px'
}}>
<h3>{product.name[i18n.language]}</h3>
<p>{product.description[i18n.language]}</p>
<div style={{ marginTop: '15px' }}>
<strong>{t('product.price')}: </strong>
{formatPrice(product.price)}
</div>
<div style={{ marginTop: '10px', fontSize: '0.9em', color: '#666' }}>
์ถ์์ผ: {formatDate(product.releaseDate)}
</div>
<div style={{ marginTop: '10px' }}>
{product.inStock ? (
<span style={{ color: 'green' }}>โ {t('product.inStock')}</span>
) : (
<span style={{ color: 'red' }}>โ {t('product.outOfStock')}</span>
)}
</div>
<button
onClick={() => console.log('Add to cart:', product.id)}
disabled={!product.inStock}
style={{
marginTop: '15px',
padding: '10px 20px',
background: product.inStock ? '#4a5568' : '#ccc',
color: 'white',
border: 'none',
borderRadius: '8px',
cursor: product.inStock ? 'pointer' : 'not-allowed',
width: '100%'
}}
>
{t('product.addToCart')}
</button>
</div>
);
};
export default ProductCard;
// 5. ์ฅ๋ฐ๊ตฌ๋ ์ปดํฌ๋ํธ (src/components/ShoppingCart.jsx)
import React from 'react';
import { useTranslation } from 'react-i18next';
const ShoppingCart = ({ items }) => {
const { t, i18n } = useTranslation();
const formatPrice = (price) => {
const currencyMap = {
ko: { currency: 'KRW', locale: 'ko-KR' },
en: { currency: 'USD', locale: 'en-US' },
ja: { currency: 'JPY', locale: 'ja-JP' }
};
const { currency, locale } = currencyMap[i18n.language] || currencyMap.en;
return new Intl.NumberFormat(locale, {
style: 'currency',
currency: currency
}).format(price);
};
const totalPrice = items.reduce((sum, item) => sum + item.price * item.quantity, 0);
const totalItems = items.reduce((sum, item) => sum + item.quantity, 0);
return (
<div style={{
border: '2px solid #e3f2fd',
borderRadius: '12px',
padding: '20px',
margin: '20px 0'
}}>
<h2>{t('cart.title')}</h2>
{items.length === 0 ? (
<p style={{ color: '#999', textAlign: 'center', padding: '40px 0' }}>
{t('cart.empty')}
</p>
) : (
<>
<div style={{ marginBottom: '15px', color: '#666' }}>
{t('cart.itemCount', { count: totalItems })}
</div>
{items.map(item => (
<div key={item.id} style={{
display: 'flex',
justifyContent: 'space-between',
padding: '10px 0',
borderBottom: '1px solid #eee'
}}>
<span>{item.name[i18n.language]} ร {item.quantity}</span>
<span>{formatPrice(item.price * item.quantity)}</span>
</div>
))}
<div style={{
marginTop: '20px',
paddingTop: '20px',
borderTop: '2px solid #4a5568',
display: 'flex',
justifyContent: 'space-between',
fontSize: '1.2em',
fontWeight: 'bold'
}}>
<span>{t('cart.total')}</span>
<span>{formatPrice(totalPrice)}</span>
</div>
<button style={{
marginTop: '20px',
padding: '12px',
background: '#4a5568',
color: 'white',
border: 'none',
borderRadius: '8px',
width: '100%',
cursor: 'pointer',
fontSize: '1.1em'
}}>
{t('cart.checkout')}
</button>
</>
)}
</div>
);
};
export default ShoppingCart;
// 6. ๋ฉ์ธ ์ฑ ์ปดํฌ๋ํธ (src/App.jsx)
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import LanguageSelector from './components/LanguageSelector';
import ProductCard from './components/ProductCard';
import ShoppingCart from './components/ShoppingCart';
import './i18n/config';
function App() {
const { t } = useTranslation();
// ์ํ ์ํ ๋ฐ์ดํฐ
const products = [
{
id: 1,
name: {
ko: '๋ฌด์ ์ด์ดํฐ',
en: 'Wireless Earbuds',
ja: 'ใฏใคใคใฌในใคใคใใณ'
},
description: {
ko: '๊ณ ์์ง ๋ธ๋ฃจํฌ์ค ์ด์ดํฐ',
en: 'High-quality Bluetooth earbuds',
ja: '้ซ้ณ่ณชBluetoothใคใคใใณ'
},
price: 89000,
releaseDate: '2024-01-15',
inStock: true
},
{
id: 2,
name: {
ko: '์ค๋งํธ์์น',
en: 'Smart Watch',
ja: 'ในใใผใใฆใฉใใ'
},
description: {
ko: '๊ฑด๊ฐ ๊ด๋ฆฌ ๊ธฐ๋ฅ์ด ์๋ ์ค๋งํธ์์น',
en: 'Smart watch with health tracking',
ja: 'ๅฅๅบท็ฎก็ๆฉ่ฝไปใในใใผใใฆใฉใใ'
},
price: 299000,
releaseDate: '2024-02-01',
inStock: true
},
{
id: 3,
name: {
ko: '๋
ธํธ๋ถ ์คํ ๋',
en: 'Laptop Stand',
ja: 'ใใผใใใฝใณใณในใฟใณใ'
},
description: {
ko: '์ธ์ฒด๊ณตํ์ ๋์์ธ์ ๋
ธํธ๋ถ ์คํ ๋',
en: 'Ergonomic laptop stand',
ja: 'ไบบ้ๅทฅๅญฆใใถใคใณใฎใใผใใใฝใณใณในใฟใณใ'
},
price: 45000,
releaseDate: '2023-12-10',
inStock: false
}
];
const [cartItems, setCartItems] = useState([
{
id: 1,
name: products[0].name,
price: products[0].price,
quantity: 2
}
]);
return (
<div style={{ maxWidth: '1200px', margin: '0 auto', padding: '20px' }}>
<header style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
marginBottom: '40px',
padding: '20px',
background: 'linear-gradient(135deg, #e8f4f8 0%, #f5e6f1 100%)',
borderRadius: '12px'
}}>
<h1 style={{ margin: 0 }}>๐ Global Shop</h1>
<LanguageSelector />
</header>
<nav style={{
display: 'flex',
gap: '20px',
marginBottom: '30px',
padding: '15px',
background: '#f8f9fa',
borderRadius: '8px'
}}>
<a href="#" style={{ textDecoration: 'none', color: '#4a5568' }}>{t('nav.home')}</a>
<a href="#" style={{ textDecoration: 'none', color: '#4a5568' }}>{t('nav.products')}</a>
<a href="#" style={{ textDecoration: 'none', color: '#4a5568' }}>{t('nav.cart')}</a>
<a href="#" style={{ textDecoration: 'none', color: '#4a5568' }}>{t('nav.account')}</a>
</nav>
<div style={{ display: 'grid', gridTemplateColumns: '2fr 1fr', gap: '30px' }}>
<div>
<h2>{t('product.title')}</h2>
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(250px, 1fr))', gap: '20px' }}>
{products.map(product => (
<ProductCard key={product.id} product={product} />
))}
</div>
</div>
<div>
<ShoppingCart items={cartItems} />
</div>
</div>
</div>
);
}
export default App;
์ด ์์ ๋ ์ค์ ๋ก ๋์ํ๋ ์์ ํ ๋ค๊ตญ์ด ์ผํ๋ชฐ์ด์์! ๐
์ธ์ด๋ฅผ ๋ฐ๊พธ๋ฉด ๋ชจ๋ ํ
์คํธ, ํตํ, ๋ ์ง ํ์์ด ์๋์ผ๋ก ๋ณ๊ฒฝ๋๋ ๊ฑธ ๋ณผ ์ ์๋ต๋๋ค. ์ด๋ฐ ์์ผ๋ก ์ค์ ํ๋ก์ ํธ์ ์ ์ฉํ๋ฉด ๋๋ ๊ฑฐ์์!
โก ์ฑ๋ฅ ์ต์ ํ ํ
๋ค๊ตญ์ด ์ง์์ ์ถ๊ฐํ๋ฉด ๋ฒ์ญ ํ์ผ ๋๋ฌธ์ ์ฑ ํฌ๊ธฐ๊ฐ ์ปค์ง ์ ์์ด์. ์ฑ๋ฅ์ ์ ์งํ๋ฉด์ i18n์ ๊ตฌํํ๋ ๋ฐฉ๋ฒ์ ์์๋ด ์๋ค! ๐
1๏ธโฃ ์ง์ฐ ๋ก๋ฉ (Lazy Loading) ๐ฆ
๋ชจ๋ ์ธ์ด ํ์ผ์ ํ ๋ฒ์ ๋ก๋ํ์ง ๋ง๊ณ , ํ์ํ ๋๋ง ๋ก๋ํ์ธ์!
// i18next ๋ฐฑ์๋ ํ๋ฌ๊ทธ์ธ ์ฌ์ฉ
import i18n from 'i18next';
import Backend from 'i18next-http-backend';
import { initReactI18next } from 'react-i18next';
i18n
.use(Backend)
.use(initReactI18next)
.init({
fallbackLng: 'en',
backend: {
// ๋ฒ์ญ ํ์ผ์ ์๋ฒ์์ ๋์ ์ผ๋ก ๋ก๋
loadPath: '/locales/{{lng}}/{{ns}}.json'
},
// ๋ค์์คํ์ด์ค๋ณ๋ก ๋ถ๋ฆฌํ์ฌ ํ์ํ ๊ฒ๋ง ๋ก๋
ns: ['common', 'auth', 'product'],
defaultNS: 'common'
});
// ํน์ ๋ค์์คํ์ด์ค๋ง ๋ก๋
i18n.loadNamespaces(['product']).then(() => {
// ์ํ ํ์ด์ง ๋ ๋๋ง
});
2๏ธโฃ ๋ฒ์ญ ํ์ผ ์์ถ ๐๏ธ
JSON ํ์ผ์ ์ต์ํํ๊ณ gzip ์์ถ์ ์ฌ์ฉํ์ธ์!
// webpack ์ค์ ์์
module.exports = {
// ...
plugins: [
new CompressionPlugin({
test: /\.json$/,
algorithm: 'gzip'
})
]
};
// ์๋ฒ ์ค์ (Express ์์)
const compression = require('compression');
app.use(compression());
3๏ธโฃ ๋ฒ์ญ ์บ์ฑ ๐พ
ํ ๋ฒ ๋ก๋ํ ๋ฒ์ญ์ ๋ธ๋ผ์ฐ์ ์ ์บ์ํ์ธ์!
// Service Worker๋ฅผ ์ฌ์ฉํ ์บ์ฑ
self.addEventListener('fetch', (event) => {
if (event.request.url.includes('/locales/')) {
event.respondWith(
caches.open('translations-v1').then((cache) => {
return cache.match(event.request).then((response) => {
return response || fetch(event.request).then((response) => {
cache.put(event.request, response.clone());
return response;
});
});
})
);
}
});
// i18next ์บ์ ์ค์
i18n.init({
cache: {
enabled: true,
expirationTime: 7 * 24 * 60 * 60 * 1000 // 7์ผ
}
});
4๏ธโฃ ๋ฒ์ญ ํค ์ต์ ํ ๐
์ค๋ณต๋ ๋ฒ์ญ์ ์ ๊ฑฐํ๊ณ ๊ณตํต ๋ฌธ๊ตฌ๋ ์ฌ์ฌ์ฉํ์ธ์!
// โ ๋์ ์์ - ์ค๋ณต๋ ๋ฒ์ญ
{
"button.save": "์ ์ฅ",
"button.saveChanges": "์ ์ฅ",
"button.saveData": "์ ์ฅ",
"form.save": "์ ์ฅ"
}
// โ
์ข์ ์์ - ์ฌ์ฌ์ฉ
{
"common.save": "์ ์ฅ",
"common.cancel": "์ทจ์"
}
// ์ปจํ
์คํธ๊ฐ ํ์ํ ๊ฒฝ์ฐ์๋ง ๋ณ๋ ํค ์ฌ์ฉ
{
"common.save": "์ ์ฅ",
"file.save": "ํ์ผ ์ ์ฅ",
"profile.save": "ํ๋กํ ์ ์ฅ"
}
5๏ธโฃ ์ฝ๋ ์คํ๋ฆฌํ
โ๏ธ
๋ผ์ฐํธ๋ณ๋ก ๋ฒ์ญ ํ์ผ์ ๋ถ๋ฆฌํ์ธ์!
// React Router์ ํจ๊ป ์ฌ์ฉ
import { lazy, Suspense } from 'react';
import { BrowserRouter, Routes, Route } from 'react-router-dom';
// ํ์ด์ง๋ณ ๋ฒ์ญ ํ์ผ ๋์ ๋ก๋
const HomePage = lazy(() => {
i18n.loadNamespaces('home');
return import('./pages/HomePage');
});
const ProductPage = lazy(() => {
i18n.loadNamespaces('product');
return import('./pages/ProductPage');
});
function App() {
return (
<BrowserRouter>
<Suspense fallback={<div>Loading...</div>}>
<Routes>
<Route path="/" element={<HomePage />} />
<Route path="/products" element={<ProductPage />} />
</Routes>
</Suspense>
</BrowserRouter>
);
}
๐ ํ ์คํธ ๋ฐ QA ์ ๋ต
๋ค๊ตญ์ด ์ ํ๋ฆฌ์ผ์ด์ ์ ํ ์คํธ๊ฐ ๋ ๋ณต์กํด์. ์ฒด๊ณ์ ์ธ ํ ์คํธ ์ ๋ต์ด ํ์ํ๋ต๋๋ค! ๐งช
์๋ํ ํ ์คํธ ์์ฑ ๐ค ๋ฒ์ญ ํค๊ฐ ๋๋ฝ๋๊ฑฐ๋ ์๋ชป๋ ๊ฒฝ์ฐ๋ฅผ ์๋์ผ๋ก ๊ฐ์งํ์ธ์!
// Jest๋ฅผ ์ฌ์ฉํ ๋ฒ์ญ ํ
์คํธ
import i18n from '../i18n/config';
describe('Translation Tests', () => {
const languages = ['ko', 'en', 'ja'];
const requiredKeys = [
'common.save',
'common.cancel',
'nav.home',
'nav.products'
];
languages.forEach(lang => {
describe(`${lang} translations`, () => {
beforeAll(() => {
i18n.changeLanguage(lang);
});
requiredKeys.forEach(key => {
test(`should have translation for ${key}`, () => {
const translation = i18n.t(key);
expect(translation).not.toBe(key); // ํค ์์ฒด๊ฐ ๋ฐํ๋๋ฉด ์ ๋จ
expect(translation).toBeTruthy();
expect(translation.length).toBeGreaterThan(0);
});
});
test('should not have missing translations', () => {
const missingKeys = [];
requiredKeys.forEach(key => {
if (i18n.t(key) === key) {
missingKeys.push(key);
}
});
expect(missingKeys).toEqual([]);
});
});
});
test('should format numbers correctly', () => {
i18n.changeLanguage('ko');
const formatted = new Intl.NumberFormat('ko-KR').format(1234567);
expect(formatted).toBe('1,234,567');
i18n.changeLanguage('de');
const formattedDE = new Intl.NumberFormat('de-DE').format(1234567);
expect(formattedDE).toBe('1.234.567');
});
test('should format dates correctly', () => {
const date = new Date('2024-01-15');
i18n.changeLanguage('ko');
const koDate = new Intl.DateTimeFormat('ko-KR').format(date);
expect(koDate).toContain('2024');
i18n.changeLanguage('en');
const enDate = new Intl.DateTimeFormat('en-US').format(date);
expect(enDate).toContain('2024');
});
});
โ ๏ธ ์๊ฐ์ ํ
์คํธ (Visual Testing)
์ธ์ด๋ง๋ค ํ
์คํธ ๊ธธ์ด๊ฐ ๋ค๋ฅด๊ธฐ ๋๋ฌธ์ UI๊ฐ ๊นจ์ง ์ ์์ด์!
- ๋
์ผ์ด๋ ์์ด๋ณด๋ค ํ๊ท 30% ๋ ๊ธธ์ด์
- ํ๊ตญ์ด/์ค๊ตญ์ด/์ผ๋ณธ์ด๋ ์ธ๋ก ๊ณต๊ฐ์ ๋ ์ฐจ์งํด์
- ์๋์ด๋ RTL์ด๋ผ ๋ ์ด์์์ด ์์ ํ ๋ฌ๋ผ์
๋ชจ๋ ์ธ์ด๋ก ์คํฌ๋ฆฐ์ท์ ์ฐ์ด์ ๋น๊ตํด๋ณด์ธ์! ๐ธ
// Playwright๋ฅผ ์ฌ์ฉํ ์๊ฐ์ ํ
์คํธ
import { test, expect } from '@playwright/test';
const languages = ['ko', 'en', 'ja', 'de', 'ar'];
languages.forEach(lang => {
test(`Visual test for ${lang}`, async ({ page }) => {
await page.goto(`http://localhost:3000?lang=${lang}`);
// ์ธ์ด๊ฐ ์ ๋๋ก ์ ์ฉ๋์๋์ง ํ์ธ
await page.waitForSelector(`[lang="${lang}"]`);
// ์ ์ฒด ํ์ด์ง ์คํฌ๋ฆฐ์ท
await expect(page).toHaveScreenshot(`homepage-${lang}.png`, {
fullPage: true
});
// ํน์ ์ปดํฌ๋ํธ ์คํฌ๋ฆฐ์ท
const productCard = page.locator('.product-card').first();
await expect(productCard).toHaveScreenshot(`product-card-${lang}.png`);
// ํ
์คํธ ์ค๋ฒํ๋ก์ฐ ์ฒดํฌ
const buttons = page.locator('button');
for (const button of await buttons.all()) {
const box = await button.boundingBox();
const text = await button.textContent();
// ๋ฒํผ ํ
์คํธ๊ฐ ๋ฒํผ ์์ญ์ ๋ฒ์ด๋์ง ์๋์ง ํ์ธ
expect(box.width).toBeGreaterThan(text.length * 5); // ๋๋ต์ ์ธ ์ฒดํฌ
}
});
});
์ค์ ์ฌ์ฉ์ ํ
์คํธ ๐ฅ
๊ฐ๋ฅํ๋ค๋ฉด ๊ฐ ์ธ์ด์ ๋ค์ดํฐ๋ธ ์คํผ์ปค์๊ฒ ํ
์คํธ๋ฅผ ๋ฐ์ผ์ธ์!
- ๋ฒ์ญ์ด ์์ฐ์ค๋ฌ์ด์ง
- ๋ฌธํ์ ์ผ๋ก ์ ์ ํ์ง
- UI๊ฐ ํด๋น ์ธ์ด๋ก ์ ์๋ํ๋์ง
์ฌ๋ฅ๋ท์์ ๋ค์ํ ์ธ์ด์ ๋ฒ์ญ๊ฐ๋ ํ
์คํฐ๋ฅผ ์ฐพ์ ์ ์์ด์! ๐
๐ ๊ณ ๊ธ ์ฃผ์ : ๋์ ์ฝํ ์ธ ๋ฒ์ญ
๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ ์ฅ๋ ์ฌ์ฉ์ ์์ฑ ์ฝํ ์ธ ๋ ์ด๋ป๊ฒ ๋ฒ์ญํ ๊น์? ๊ณ ๊ธ ๊ธฐ๋ฒ๋ค์ ์์๋ด ์๋ค! ๐
๋ฐ์ดํฐ๋ฒ ์ด์ค ์คํค๋ง ์ค๊ณ ๐๏ธ
๋ค๊ตญ์ด ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ๋ ๋ฐฉ๋ฒ์ ์ฌ๋ฌ ๊ฐ์ง๊ฐ ์์ด์!
// ๋ฐฉ๋ฒ 1: JSON ์ปฌ๋ผ ์ฌ์ฉ (PostgreSQL, MySQL 8.0+)
CREATE TABLE products (
id SERIAL PRIMARY KEY,
name JSONB NOT NULL,
description JSONB NOT NULL,
price DECIMAL(10, 2) NOT NULL,
created_at TIMESTAMP DEFAULT NOW()
);
-- ๋ฐ์ดํฐ ์ฝ์
INSERT INTO products (name, description, price) VALUES (
'{"ko": "๋ฌด์ ์ด์ดํฐ", "en": "Wireless Earbuds", "ja": "ใฏใคใคใฌในใคใคใใณ"}',
'{"ko": "๊ณ ์์ง ๋ธ๋ฃจํฌ์ค ์ด์ดํฐ", "en": "High-quality Bluetooth earbuds", "ja": "้ซ้ณ่ณชBluetoothใคใคใใณ"}',
89000
);
-- ํน์ ์ธ์ด๋ก ์กฐํ
SELECT
id,
name->>'ko' as name,
description->>'ko' as description,
price
FROM products;
// ๋ฐฉ๋ฒ 2: ๋ณ๋ ๋ฒ์ญ ํ
์ด๋ธ ์ฌ์ฉ
CREATE TABLE products (
id SERIAL PRIMARY KEY,
price DECIMAL(10, 2) NOT NULL,
created_at TIMESTAMP DEFAULT NOW()
);
CREATE TABLE product_translations (
id SERIAL PRIMARY KEY,
product_id INTEGER REFERENCES products(id),
language_code VARCHAR(5) NOT NULL,
name VARCHAR(255) NOT NULL,
description TEXT,
UNIQUE(product_id, language_code)
);
-- ๋ฐ์ดํฐ ์ฝ์
INSERT INTO products (price) VALUES (89000);
INSERT INTO product_translations (product_id, language_code, name, description) VALUES
(1, 'ko', '๋ฌด์ ์ด์ดํฐ', '๊ณ ์์ง ๋ธ๋ฃจํฌ์ค ์ด์ดํฐ'),
(1, 'en', 'Wireless Earbuds', 'High-quality Bluetooth earbuds'),
(1, 'ja', 'ใฏใคใคใฌในใคใคใใณ', '้ซ้ณ่ณชBluetoothใคใคใใณ');
-- ์กฐ์ธํ์ฌ ์กฐํ
SELECT
p.id,
p.price,
pt.name,
pt.description
FROM products p
JOIN product_translations pt ON p.id = pt.product_id
WHERE pt.language_code = 'ko';
API ์ค๊ณ ๐
ํด๋ผ์ด์ธํธ๊ฐ ์ํ๋ ์ธ์ด๋ก ๋ฐ์ดํฐ๋ฅผ ๋ฐ์ ์ ์๋๋ก API๋ฅผ ์ค๊ณํ์ธ์!
// Express.js API ์์
const express = require('express');
const app = express();
// ๋ฏธ๋ค์จ์ด: ์์ฒญ ์ธ์ด ๊ฐ์ง
app.use((req, res, next) => {
// 1. ์ฟผ๋ฆฌ ํ๋ผ๋ฏธํฐ ํ์ธ
req.locale = req.query.lang
// 2. Accept-Language ํค๋ ํ์ธ
|| req.headers['accept-language']?.split(',')[0]?.split('-')[0]
// 3. ๊ธฐ๋ณธ๊ฐ
|| 'en';
next();
});
// ์ํ ๋ชฉ๋ก API
app.get('/api/products', async (req, res) => {
const locale = req.locale;
// JSON ์ปฌ๋ผ ๋ฐฉ์
const products = await db.query(`
SELECT
id,
name->>'${locale}' as name,
description->>'${locale}' as description,
price
FROM products
`);
res.json(products);
});
// ๋ณ๋ ํ
์ด๋ธ ๋ฐฉ์
app.get('/api/products/:id', async (req, res) => {
const { id } = req.params;
const locale = req.locale;
const product = await db.query(`
SELECT
p.id,
p.price,
pt.name,
pt.description
FROM products p
LEFT JOIN product_translations pt
ON p.id = pt.product_id
AND pt.language_code = $1
WHERE p.id = $2
`, [locale, id]);
// ๋ฒ์ญ์ด ์์ผ๋ฉด ๊ธฐ๋ณธ ์ธ์ด๋ก ํด๋ฐฑ
if (!product.name) {
const fallback = await db.query(`
SELECT name, description
FROM product_translations
WHERE product_id = $1 AND language_code = 'en'
`, [id]);
product.name = fallback.name;
product.description = fallback.description;
}
res.json(product);
});
์๋ ๋ฒ์ญ ํตํฉ ๐ค
Google Translate API๋ DeepL API๋ฅผ ์ฌ์ฉํ์ฌ ์๋ ๋ฒ์ญ์ ์ ๊ณตํ ์ ์์ด์!
// Google Cloud Translation API ์ฌ์ฉ ์์
const { Translate } = require('@google-cloud/translate').v2;
const translate = new Translate({ key: process.env.GOOGLE_API_KEY });
async function translateText(text, targetLanguage) {
try {
const [translation] = await translate.translate(text, targetLanguage);
return translation;
} catch (error) {
console.error('Translation error:', error);
return text; // ์คํจ ์ ์๋ณธ ๋ฐํ
}
}
// ์ํ ๋ฑ๋ก ์ ์๋ ๋ฒ์ญ
app.post('/api/products', async (req, res) => {
const { name, description, price, sourceLanguage } = req.body;
const targetLanguages = ['ko', 'en', 'ja', 'zh'];
// ์ํ ์์ฑ
const product = await db.query(
'INSERT INTO products (price) VALUES ($1) RETURNING id',
[price]
);
// ์๋ณธ ์ธ์ด ์ ์ฅ
await db.query(
'INSERT INTO product_translations (product_id, language_code, name, description) VALUES ($1, $2, $3, $4)',
[product.id, sourceLanguage, name, description]
);
// ๋ค๋ฅธ ์ธ์ด๋ก ์๋ ๋ฒ์ญ
for (const lang of targetLanguages) {
if (lang === sourceLanguage) continue;
const translatedName = await translateText(name, lang);
const translatedDescription = await translateText(description, lang);
await db.query(
'INSERT INTO product_translations (product_id, language_code, name, description) VALUES ($1, $2, $3, $4)',
[product.id, lang, translatedName, translatedDescription]
);
}
res.json({ success: true, productId: product.id });
});
// ์ฃผ์: ์๋ ๋ฒ์ญ์ ์๋ฒฝํ์ง ์์ผ๋ฏ๋ก
// ๋์ค์ ์ ๋ฌธ ๋ฒ์ญ๊ฐ๊ฐ ๊ฒํ ํ๊ณ ์์ ํ ์ ์๋ ๊ธฐ๋ฅ ํ์!
app.put('/api/products/:id/translations/:lang', async (req, res) => {
const { id, lang } = req.params;
const { name, description, reviewed } = req.body;
await db.query(
`UPDATE product_translations
SET name = $1, description = $2, reviewed = $3, updated_at = NOW()
WHERE product_id = $4 AND language_code = $5`,
[name, description, reviewed, id, lang]
);
res.json({ success: true });
});
โ ๏ธ ์๋ ๋ฒ์ญ ์ฌ์ฉ ์ ์ฃผ์์ฌํญ
1. ์๋ ๋ฒ์ญ์ ์ฐธ๊ณ ์ฉ์ผ๋ก๋ง ์ฌ์ฉํ์ธ์
2. ์ค์ํ ์ฝํ
์ธ ๋ ๋ฐ๋์ ์ ๋ฌธ ๋ฒ์ญ๊ฐ์ ๊ฒํ ๊ฐ ํ์ํด์
3. ๋ฌธํ์ ๋งฅ๋ฝ์ด๋ ๋์์ค๋ ์๋ ๋ฒ์ญ์ผ๋ก ์ก์๋ด๊ธฐ ์ด๋ ค์์
4. ๋ฒ๋ฅ ๋ฌธ์, ์๋ฃ ์ ๋ณด ๋ฑ์ ์ ๋ ์๋ ๋ฒ์ญ๋ง ์ฌ์ฉํ๋ฉด ์ ๋ผ์!
์ฌ๋ฅ๋ท์์ ์ ๋ฌธ ๋ฒ์ญ๊ฐ๋ฅผ ์ฐพ์ ํ์ง ๋์ ๋ฒ์ญ์ ๋ฐ์๋ณด์ธ์! ๐
๐ก ์ค๋ฌด ํ๊ณผ ๋ฒ ์คํธ ํ๋ํฐ์ค
์ค์ ํ๋ก์ ํธ์์ i18n/l10n์ ๊ตฌํํ๋ฉด์ ๋ฐฐ์ด ์์คํ ๊ตํ๋ค์ ๊ณต์ ํ ๊ฒ์! ๐
โ DO: ํด์ผ ํ ๊ฒ๋ค
1. ํ๋ก์ ํธ ์ด๊ธฐ๋ถํฐ ๊ตญ์ ํ๋ฅผ ๊ณ ๋ คํ์ธ์
๋์ค์ ์ถ๊ฐํ๋ ๊ฒ๋ณด๋ค ์ฒ์๋ถํฐ ์ค๊ณํ๋ ๊ฒ ํจ์ฌ ์ฌ์์!
2. ๋ฒ์ญ ํค๋ ์๋ฏธ ์๊ฒ ์์ฑํ์ธ์
'text1', 'label2' ๊ฐ์ ์ด๋ฆ ๋์ 'auth.login.button.submit' ์ฒ๋ผ ๋ช
ํํ๊ฒ!
3. ์ปจํ
์คํธ๋ฅผ ์ ๊ณตํ์ธ์
๋ฒ์ญ๊ฐ๊ฐ ๋ฌธ๋งฅ์ ์ดํดํ ์ ์๋๋ก ์ฃผ์์ด๋ ์ค๋ช
์ ์ถ๊ฐํ์ธ์.
4. ๋ณต์ํ ๊ท์น์ ํ์ฉํ์ธ์
์ธ์ด๋ง๋ค ๋ณต์ํ ๊ท์น์ด ๋ค๋ฅด๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋ณต์ํ ๊ธฐ๋ฅ์ ์ฌ์ฉํ์ธ์.
5. ๋ ์ง, ์๊ฐ, ํตํ๋ ๋ก์ผ์ผ API๋ฅผ ์ฌ์ฉํ์ธ์
์ง์ ํฌ๋งทํ
ํ์ง ๋ง๊ณ Intl API๋ฅผ ํ์ฉํ์ธ์.
6. RTL ์ธ์ด๋ฅผ ๊ณ ๋ คํ์ธ์
์๋์ด, ํ๋ธ๋ฆฌ์ด ๋ฑ์ ์ง์ํ ๊ณํ์ด๋ผ๋ฉด ์ฒ์๋ถํฐ ๋
ผ๋ฆฌ์ CSS ์์ฑ์ ์ฌ์ฉํ์ธ์.
7. ์ ๊ธฐ์ ์ผ๋ก ๋ฒ์ญ์ ๊ฒ์ฆํ์ธ์
์๋ํ๋ ํ
์คํธ๋ก ๋๋ฝ๋ ๋ฒ์ญ์ ์ฐพ์๋ด์ธ์.
8. ๋ฒ์ญ ๋ฒ์ ๊ด๋ฆฌ๋ฅผ ํ์ธ์
Git์ผ๋ก ๋ฒ์ญ ํ์ผ๋ ๋ฒ์ ๊ด๋ฆฌํ๊ณ , ๋ณ๊ฒฝ ์ด๋ ฅ์ ์ถ์ ํ์ธ์.
โ DON'T: ํ์ง ๋ง์์ผ ํ ๊ฒ๋ค
1. ๋ฌธ์์ด์ ์ฐ๊ฒฐํ์ง ๋ง์ธ์
"Hello " + name + "!" ๋์ ํ๋ผ๋ฏธํฐ ํฌ๋งทํ
์ ์ฌ์ฉํ์ธ์.
2. ์ด๋ฏธ์ง์ ํ
์คํธ๋ฅผ ๋ฃ์ง ๋ง์ธ์
๋ฒ์ญํ ์ ์์ผ๋ SVG๋ CSS๋ก ํ
์คํธ๋ฅผ ํํํ์ธ์.
3. ๊ณ ์ ๋ ๋๋น/๋์ด๋ฅผ ์ฌ์ฉํ์ง ๋ง์ธ์
์ธ์ด๋ง๋ค ํ
์คํธ ๊ธธ์ด๊ฐ ๋ค๋ฅด๋ ์ ์ฐํ ๋ ์ด์์์ ์ฌ์ฉํ์ธ์.
4. ๋ฌธํ์ ์ผ๋ก ๋ฏผ๊ฐํ ์ด๋ฏธ์ง๋ฅผ ๋ฌด๋ถ๋ณํ๊ฒ ์ฌ์ฉํ์ง ๋ง์ธ์
์๋์, ์์, ์์ง ๋ฑ์ ๋ฌธํ๋ง๋ค ์๋ฏธ๊ฐ ๋ค๋ฅผ ์ ์์ด์.
5. ์๋ ๋ฒ์ญ๋ง ๋ฏฟ์ง ๋ง์ธ์
์ฐธ๊ณ ์ฉ์ผ๋ก๋ง ์ฌ์ฉํ๊ณ ์ ๋ฌธ๊ฐ์ ๊ฒํ ๋ฅผ ๋ฐ์ผ์ธ์.
6. ๋ฒ์ญ ํค๋ฅผ ์์ฃผ ๋ณ๊ฒฝํ์ง ๋ง์ธ์
ํ ๋ฒ ์ ํ ํค๋ ๊ฐ๊ธ์ ์ ์งํ์ธ์. ๋ณ๊ฒฝํ๋ฉด ๋ชจ๋ ๋ฒ์ญ์ ๋ค์ ํด์ผ ํด์.
7. ํ๋์ฝ๋ฉ๋ URL์ ์ฌ์ฉํ์ง ๋ง์ธ์
'/ko/products' ๊ฐ์ URL ๊ตฌ์กฐ๋ ๊ตญ์ ํ๋ฅผ ๊ณ ๋ คํด์ ์ค๊ณํ์ธ์.
8. ์ฑ๋ฅ์ ๋ฌด์ํ์ง ๋ง์ธ์
๋ชจ๋ ๋ฒ์ญ์ ํ ๋ฒ์ ๋ก๋ํ๋ฉด ์ด๊ธฐ ๋ก๋ฉ์ด ๋๋ ค์ ธ์.
๐ ์ฒดํฌ๋ฆฌ์คํธ
| ํญ๋ชฉ | ํ์ธ | ์ค๋ช |
|---|---|---|
| ๋ฌธ์์ด ์ธ๋ถํ | โ | ๋ชจ๋ UI ํ ์คํธ๊ฐ ๋ฒ์ญ ํ์ผ๋ก ๋ถ๋ฆฌ๋์๋์? |
| ์ ๋์ฝ๋ ์ง์ | โ | UTF-8 ์ธ์ฝ๋ฉ์ ์ฌ์ฉํ๊ณ ์๋์? |
| ๋ก์ผ์ผ ๊ฐ์ง | โ | ์ฌ์ฉ์ ์ธ์ด๋ฅผ ์๋์ผ๋ก ๊ฐ์งํ๋์? |
| ๋ ์ง/์๊ฐ ํ์ | โ | Intl API๋ฅผ ์ฌ์ฉํ์ฌ ๋ก์ผ์ผ๋ณ๋ก ํฌ๋งทํ๋์? |
| ํตํ ํ์ | โ | ๊ฐ ์ง์ญ์ ํตํ์ ํ์์ ์ฌ๋ฐ๋ฅด๊ฒ ํ์ํ๋์? |
| ๋ณต์ํ ์ฒ๋ฆฌ | โ | ์ธ์ด๋ณ ๋ณต์ํ ๊ท์น์ ์ ์ฉํ๋์? |
| RTL ์ง์ | โ | ์๋์ด ๋ฑ RTL ์ธ์ด๋ฅผ ์ง์ํ๋์? |
| ์ ์ฐํ ๋ ์ด์์ | โ | ํ ์คํธ ๊ธธ์ด ๋ณํ์ ๋์ํ ์ ์๋์? |
| ๋ฒ์ญ ๊ฒ์ฆ | โ | ์๋ํ๋ ํ ์คํธ๊ฐ ์๋์? |
| ์ฑ๋ฅ ์ต์ ํ | โ | ์ง์ฐ ๋ก๋ฉ๊ณผ ์บ์ฑ์ ๊ตฌํํ๋์? |
| ํด๋ฐฑ ์ ๋ต | โ | ๋ฒ์ญ์ด ์์ ๋ ๋์ฒด ์ธ์ด๊ฐ ํ์๋๋์? |
| ๋ฌธํ์ ๊ณ ๋ ค | โ | ์์, ์ด๋ฏธ์ง, ์์ง์ด ์ ์ ํ๊ฐ์? |
๐ฌ ๋ง๋ฌด๋ฆฌํ๋ฉฐ
์! ์ฌ๊ธฐ๊น์ง ์ค์๋๋ผ ์๊ณ ๋ง์ผ์
จ์ด์! ๐
๊ตญ์ ํ์ ์ง์ญํ๋ ์ฒ์์๋ ๋ณต์กํด ๋ณด์ด์ง๋ง, ์ฒด๊ณ์ ์ผ๋ก ์ ๊ทผํ๋ฉด ์ถฉ๋ถํ ๊ตฌํํ ์ ์๋ต๋๋ค. ํต์ฌ์ ์ฒ์๋ถํฐ ๊ธ๋ก๋ฒ์ ์ผ๋์ ๋๊ณ ์ค๊ณํ๋ ๊ฒ์ด์์!
์ค๋ ๋ฐฐ์ด ๋ด์ฉ์ ์ ๋ฆฌํ๋ฉด:
๐ i18n(๊ตญ์ ํ)๋ ๋ค์ํ ์ธ์ด๋ฅผ ์ง์ํ ์ ์๋ ๊ธฐ๋ฐ์ ๋ง๋๋ ๊ฒ
๐บ๏ธ l10n(์ง์ญํ)๋ ํน์ ์ง์ญ์ ๋ง๊ฒ ์ธ๋ฐํ๊ฒ ์กฐ์ ํ๋ ๊ฒ
๐ ๏ธ ๊ฐ ์ธ์ด์ ํ๋ ์์ํฌ๋ง๋ค ํ๋ฅญํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ค์ด ์์ด์
โก ์ฑ๋ฅ ์ต์ ํ์ ํ
์คํธ๋ ์์ง ๋ง์ธ์
๐ก ์ค๋ฌด ๋ฒ ์คํธ ํ๋ํฐ์ค๋ฅผ ๋ฐ๋ฅด๋ฉด ์ค์๋ฅผ ์ค์ผ ์ ์์ด์
๊ธ๋ก๋ฒ ์์ฅ์ ๋ชฉํ๋ก ํ๋ ์ฌ๋ฌ๋ถ์ ํ๋ก์ ํธ๊ฐ ์ฑ๊ณตํ๊ธธ ๋ฐ๋๋๋ค! ๐
ํน์ ๋ฒ์ญ์ด๋ ๊ตญ์ ํ ๊ด๋ จํด์ ๋์์ด ํ์ํ๋ค๋ฉด, ์ฌ๋ฅ๋ท์์ ์ ๋ฌธ๊ฐ๋ค์ ์ฐพ์๋ณด์ธ์. ๋ฒ์ญ๊ฐ, ๋ก์ปฌ๋ผ์ด์ ์ด์
์ ๋ฌธ๊ฐ, ๋ค๊ตญ์ด ํ
์คํฐ ๋ฑ ๋ค์ํ ์ฌ๋ฅ์ ๊ฐ์ง ๋ถ๋ค์ด ์ฌ๋ฌ๋ถ์ ๊ธฐ๋ค๋ฆฌ๊ณ ์๋ต๋๋ค! ๐
์ฌ๋ฌ๋ถ์ ์ฑ์ด ์ ์ธ๊ณ ์ฌ์ฉ์๋ค์๊ฒ ์ฌ๋๋ฐ๋ ๊ทธ๋ ๊น์ง, ํ์ดํ
! ๐ชโจ
๐ Happy Coding & Global Success! ๐
๊ด๋ จ ํค์๋
๋๊ธ ์์ฑ
์ด ๊ธ์ ๋ํ ์ฌ๋ฌ๋ถ์ ์๊ฐ์ ๋ค๋ ค์ฃผ์ธ์
๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค
๋๊ธ์ ์์ฑํ๋ ค๋ฉด ๋จผ์ ๋ก๊ทธ์ธํด์ฃผ์ธ์.
๋๊ธ 0
์ง์์ธ์ ์ฒ - ์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
- ์ ์๊ถ ๋ฐ ์์ ๊ถ: ๋ณธ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ๋ ์ AI ๊ธฐ์ ๋ก ์์ฑ๋์์ผ๋ฉฐ, ๋ํ๋ฏผ๊ตญ ์ ์๊ถ๋ฒ ๋ฐ ๊ตญ์ ์ ์๊ถ ํ์ฝ์ ์ํด ๋ณดํธ๋ฉ๋๋ค.
- AI ์์ฑ ์ปจํ ์ธ ์ ๋ฒ์ ์ง์: ๋ณธ AI ์์ฑ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ์ง์ ์ฐฝ์๋ฌผ๋ก ์ธ์ ๋๋ฉฐ, ๊ด๋ จ ๋ฒ๊ท์ ๋ฐ๋ผ ์ ์๊ถ ๋ณดํธ๋ฅผ ๋ฐ์ต๋๋ค.
- ์ฌ์ฉ ์ ํ: ์ฌ๋ฅ๋ท์ ๋ช ์์ ์๋ฉด ๋์ ์์ด ๋ณธ ์ปจํ ์ธ ๋ฅผ ๋ณต์ , ์์ , ๋ฐฐํฌ, ๋๋ ์์ ์ ์ผ๋ก ํ์ฉํ๋ ํ์๋ ์๊ฒฉํ ๊ธ์ง๋ฉ๋๋ค.
- ๋ฐ์ดํฐ ์์ง ๊ธ์ง: ๋ณธ ์ปจํ ์ธ ์ ๋ํ ๋ฌด๋จ ์คํฌ๋ํ, ํฌ๋กค๋ง, ๋ฐ ์๋ํ๋ ๋ฐ์ดํฐ ์์ง์ ๋ฒ์ ์ ์ฌ์ ๋์์ด ๋ฉ๋๋ค.
- AI ํ์ต ์ ํ: ์ฌ๋ฅ๋ท์ AI ์์ฑ ์ปจํ ์ธ ๋ฅผ ํ AI ๋ชจ๋ธ ํ์ต์ ๋ฌด๋จ ์ฌ์ฉํ๋ ํ์๋ ๊ธ์ง๋๋ฉฐ, ์ด๋ ์ง์ ์ฌ์ฐ๊ถ ์นจํด๋ก ๊ฐ์ฃผ๋ฉ๋๋ค.
์์ง ๋๊ธ์ด ์์ต๋๋ค.