Notice
Recent Posts
Recent Comments
Link
250x250
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- window 정책변경
- XEIcon
- npm start
- react npm install
- 글자들여쓰기
- package.json
- npm install
- 정적객체
- slickslider
- googleicon
- 동적객체
- maxwidth
- vscode git clone
- MediaQuery
- 이미지반응형
- Git clone
- 아이콘사용법
- owlcarousel
- node 오류
- 그누보드반응형
- npm install 문제
- 웹아이콘
- minwidth
- legacy-peer
- 단어단위로떨어지기
- 의존성문제
- node설치
- fontawesome
- git lab clone
- 플러그인
Archives
- Today
- Total
어쩌다 알게 된 ƪ(•̃͡•̃͡ ƪ
🟦 [React] useTranslation() 란? 국제화, 다국어 번역 본문
728x90
useTranslation()
✔ useTranslation은 react-i18next에서 제공하는 React Hook
✔ 다국어 번역을 쉽게 할 수 있도록 도와주는 기능
경로:
📂 public/locales/en/translation.json
📂 public/locales/ko/translation.json
👇 예제 👇
import { useTranslation } from 'react-i18next';
const MyComponent = () => {
const { t } = useTranslation(); // 기본적으로 'translation' 네임스페이스를 사용
return <h1>{t('welcome')}</h1>; // 'welcome' 키에 해당하는 번역된 문장을 가져옴
};
=> 불러오는 번역 파일( translation.json )에 저장해 놓았을 때,
언어 설정을 사용자 페이지에서 한국어로 바꾸면 환영합니다 라고 바뀜
📂 public/locales/ko/translation.json
{
"welcome": "환영합니다"
}
useTranslation([ ' ', ' ' ])
const { t } = useTranslation(['translation', 'menu']);
=> translation.js과 menu.js 둘다 참조
👇 예제 👇
const { t } = useTranslation(['translation', 'menu']);
return(
<span className='custom-number3-text text-nowrap'>{t('welcome')}</span>
<span className='custom-number3-text text-nowrap'>{t('home')}</span>
)
📂 public/locales/ko/translation.json
📂 public/locales/en/translation.json
{
"welcome": "환영합니다",
"logout": "로그아웃"
}
📂 public/locales/ko/menu.json
📂 public/locales/en/menu.json
{
"home": "홈",
"settings": "설정"
}
728x90
'개발 > 🟦 React' 카테고리의 다른 글
| [Node.js] windows에서 처음 사용할 때 발생하는 문제/ 실행 정책 변경 명령어 입력 (1) | 2025.03.30 |
|---|---|
| 🟦 [React] 어떤 빌드 도구를 사용하는지 알아보는 법 (ex. Vite, Next.js, CRA) (0) | 2025.03.29 |
| 🟦 [React] npm install 패키지 의존성 오류 / npm install --legacy-peer-deps 명령어 (0) | 2025.03.27 |
| 🟦 [React] input에서 Enter시 함수 실행하기 (0) | 2025.03.24 |
| 🟦 [React] 지역변수를 전역변수로 만들고 싶을 때 (1) | 2025.03.24 |
Comments
