feat: added i18n

This commit is contained in:
siujamo
2026-01-19 14:45:49 +08:00
parent f52ca401cf
commit b7ecd69469
6 changed files with 211 additions and 1 deletions
+36
View File
@@ -0,0 +1,36 @@
import i18n from "i18next"
import { initReactI18next } from "react-i18next"
import LanguageDetector from "i18next-browser-languagedetector"
// Import translation files
import BritishEnglishTranslations from "./locales/BritishEnglish.json"
import SimplifiedChineseTranslations from "./locales/SimplifiedChinese.json"
const resources = {
"en-GB": {
translation: BritishEnglishTranslations as Record<string, unknown>,
},
"zh-CN": {
translation: SimplifiedChineseTranslations as Record<string, unknown>,
},
} as const
void i18n
.use(LanguageDetector)
.use(initReactI18next)
.init({
resources,
fallbackLng: "en-GB",
debug: process.env.NODE_ENV === "development",
interpolation: {
escapeValue: false, // React already does escaping
},
detection: {
order: ["localStorage", "navigator", "htmlTag"],
caches: ["localStorage"],
},
})
export default i18n
+47
View File
@@ -0,0 +1,47 @@
{
"app": {
"title": "DevHub",
"pageTitle": "DevHub",
"copyright": "© {{year}} OnixByte. Built with React & TypeScript."
},
"navigation": {
"home": "Home"
},
"language": {
"switch": "Switch Language",
"english": "English (Great Britain)",
"chinese": "简体中文"
},
"bmi": {
"title": "BMI Calculator",
"description": "Calculate your Body Mass Index (BMI) to assess your weight status and health.",
"weight": {
"label": "Weight",
"placeholder": "Enter your weight"
},
"height": {
"label": "Height",
"placeholder": "Enter your height"
},
"calculate": "Calculate BMI",
"reset": "Reset",
"result": {
"title": "Your BMI Result"
},
"category": {
"underweight": "Underweight",
"normal": "Normal Weight",
"overweight": "Overweight",
"obese": "Obese"
},
"advice": {
"underweight": "You may need to gain weight. Consider consulting with a healthcare professional for personalised advice.",
"normal": "You have a healthy weight for your height. Maintain your current lifestyle with regular exercise and balanced nutrition.",
"overweight": "You may benefit from losing some weight. Consider increasing physical activity and improving your diet.",
"obese": "You may be at increased health risk. It's recommended to consult with a healthcare professional for guidance."
},
"scale": {
"title": "BMI Categories"
}
}
}
@@ -0,0 +1,47 @@
{
"app": {
"title": "DevHub",
"pageTitle": "DevHub",
"copyright": "© {{year}} OnixByte。 使用 React 和 TypeScript 构建。"
},
"navigation": {
"home": "首页"
},
"language": {
"switch": "切换语言",
"english": "English (Great Britain)",
"chinese": "简体中文"
},
"bmi": {
"title": "BMI 计算器",
"description": "计算您的身体质量指数(BMI)以评估您的体重状态和健康状况。",
"weight": {
"label": "体重",
"placeholder": "请输入您的体重"
},
"height": {
"label": "身高",
"placeholder": "请输入您的身高"
},
"calculate": "计算 BMI",
"reset": "重置",
"result": {
"title": "您的 BMI 结果"
},
"category": {
"underweight": "体重过轻",
"normal": "正常体重",
"overweight": "超重",
"obese": "肥胖"
},
"advice": {
"underweight": "您可能需要增加体重。建议咨询医疗专业人士获取个性化建议。",
"normal": "您的体重对于您的身高来说是健康的。保持目前的生活方式,规律运动和均衡营养。",
"overweight": "您可能需要减轻一些体重。建议增加体育活动并改善饮食。",
"obese": "您可能面临健康风险增加。建议咨询医疗专业人士获取指导。"
},
"scale": {
"title": "BMI 分类"
}
}
}
+2 -1
View File
@@ -1 +1,2 @@
import "./dayjs"
import "./dayjs"
import "./i18n"