Lingo.dev + .ts (TypeScript)
Lingo.dev CLI는 타입 정의, 객체 구조 및 TypeScript 특정 구문을 보존하면서 TypeScript 로케일 파일을 번역합니다. CLI는 TypeScript 타입 검사 및 추론을 유지하고, 모든 TypeScript 구문 및 기능을 지원하며, 기본 및 명명된 내보내기와 함께 작동하고, 템플릿 문자열 및 보간을 올바르게 처리하며, TypeScript 컴파일 프로세스와 원활하게 통합됩니다.
빠른 설정
TypeScript 로케일 파일 구성:
{
"locale": {
"source": "en",
"targets": ["es", "fr", "de"]
},
"buckets": {
"typescript": {
"include": ["src/locales/[locale].ts"]
}
}
}
주의사항: [locale]
은 CLI 실행 중에 실제 로케일로 대체되므로 구성에 그대로 유지해야 하는 플레이스홀더입니다.
TypeScript 파일 번역
npx lingo.dev@latest i18n
문자열 내용을 번역하는 동안 TypeScript 구문, 타입 주석 및 모듈 내보내기를 보존합니다.
TypeScript 구조 지원
객체 내보내기 패턴
export const messages = {
common: {
save: "저장",
cancel: "취소",
delete: "삭제",
},
auth: {
login: "로그인",
register: "계정 생성",
},
} as const;
인터페이스 기반 접근 방식
interface Messages {
welcome: string;
itemCount: (count: number) => string;
}
export const en: Messages = {
welcome: "플랫폼에 오신 것을 환영합니다",
itemCount: (count: number) => `${count}개의 항목이 있습니다`,
};
템플릿 리터럴 지원
export const messages = {
greeting: (name: string) => `안녕하세요, ${name}님!`,
notification: `${count}개의 새 메시지가 있습니다`,
path: `/users/${userId}/profile`,
};
타입 안전성 보존
Const 단언
export const locale = {
buttons: {
submit: "양식 제출",
reset: "초기화",
},
} as const;
type LocaleKeys = typeof locale;
타입 정보 및 const 단언이 그대로 유지됩니다.
함수 정의
export const t = {
welcome: (name: string): string => `Welcome, ${name}!`,
pluralize: (count: number): string =>
count === 1 ? "1 item" : `${count} items`,
};
함수 시그니처와 반환 타입은 보존됩니다.
고급 구성
다중 TypeScript 파일
"typescript": {
"include": [
"src/locales/[locale].ts",
"src/translations/[locale]/*.ts"
]
}
타입 정의 잠금
"typescript": {
"include": ["src/locales/[locale].ts"],
"lockedKeys": ["__type", "metadata"]
}