sonamu.config.ts ์ค์
sonamu.config.ts์์ i18n ์ต์
์ ํ์ฑํํฉ๋๋ค:
๋๋ ํ ๋ฆฌ ๊ตฌ์กฐ
i18n์ ํ์ฑํํ๋ฉดapi/src/i18n/ ๋๋ ํ ๋ฆฌ๊ฐ ํ์ํฉ๋๋ค:
๋์ ๋๋ฆฌ ํ์ผ ์์ฑ
defaultLocale ๋์ ๋๋ฆฌ (ko.ts)
๋ค๋ฅธ locale ๋์ ๋๋ฆฌ (en.ts)
defineLocale์ sd.generated.ts์์ export๋๋ฉฐ, defaultLocale์ ํค๋ฅผ ๊ธฐ์ค์ผ๋ก ํ์
์ฒดํฌ๋ฅผ
์ ๊ณตํฉ๋๋ค.Locale ์ค์
ํ๋ก ํธ์๋ (ํด๋ผ์ด์ธํธ)
sd.generated.ts์๋ ํด๋ผ์ด์ธํธ ์ธก locale ๊ด๋ฆฌ๋ฅผ ์ํ setLocale๊ณผ getCurrentLocale ํจ์๊ฐ ํฌํจ๋ฉ๋๋ค:
sonamu.shared.ts์ axios interceptor๊ฐ ๋ชจ๋ API ์์ฒญ์ Accept-Language ํค๋๋ฅผ ์๋์ผ๋ก ์ถ๊ฐํฉ๋๋ค:
setLocale("en")์ ํธ์ถํ ๋ค์ ๋ชจ๋ API ์์ฒญ์ Accept-Language: en ํค๋๋ฅผ ํฌํจํฉ๋๋ค.
๋ฐฑ์๋ (์๋ฒ)
์์ฒญ๋ณ๋ก locale์ ์ค์ ํ๋ ค๋ฉด ๋ฏธ๋ค์จ์ด์์ Context๋ฅผ ๊ตฌ์ฑํฉ๋๋ค:ํด๋ผ์ด์ธํธ์์
setLocale()๋ก locale์ ์ค์ ํ๋ฉด, axios interceptor๊ฐ Accept-Language ํค๋๋ฅผ
์๋ ์ ๋ฌํ๊ณ , ์๋ฒ์ locale ๋ฏธ๋ค์จ์ด๊ฐ ์ด๋ฅผ ์ฝ์ด SD() ํธ์ถ ์ ํด๋น ์ธ์ด์ ๋ฒ์ญ์ ๋ฐํํฉ๋๋ค.
๋ณ๋์ ์ถ๊ฐ ์ค์ ์์ด ํด๋ผ์ด์ธํธ-์๋ฒ ๊ฐ locale์ด ๋๊ธฐํ๋ฉ๋๋ค.์ด๊ธฐํ ํ์ธ
์ค์ ์ด ์๋ฃ๋๋ฉดpnpm sync๋ฅผ ์คํํ์ฌ sd.generated.ts๊ฐ ์์ฑ๋๋์ง ํ์ธํฉ๋๋ค:
sd.generated.ts์๋ ๋ค์์ด ํฌํจ๋ฉ๋๋ค:
- Entity์์ ์ถ์ถํ ๋ผ๋ฒจ (
entityLabels) SD()ํจ์localizedColumn()ํจ์defineLocale()ํจ์
SD ํจ์ ์ฌ์ฉ๋ฒ
๋์
๋๋ฆฌ ์์ฑ ๋ฐ ์ฌ์ฉ
Entity ๋ผ๋ฒจ
์๋ ์ถ์ถ๋๋ ๋ผ๋ฒจ