前端国际化实现:别再只支持中文了

前端国际化实现:别再只支持中文了

前端国际化实现:别再只支持中文了

毒舌时刻

这代码写得跟网红滤镜似的——仅供参考。

各位前端同行,咱们今天聊聊前端国际化。别告诉我你的应用只支持中文,那感觉就像只卖一种口味的冰淇淋——单调又无趣。

为什么你需要国际化

最近看到一个项目,所有文本都硬编码在代码里,要支持英文时傻眼了,我差点当场去世。我就想问:你是在开发应用还是在开发中文专用软件?

反面教材

// 反面教材:硬编码文本 function LoginForm() { return ( <form> <h1>登录</h1> <input placeholder="请输入邮箱" /> <input placeholder="请输入密码" type="password" /> <button>登录</button> <p>还没有账号?<a href="/register">立即注册</a></p> </form> ); } 

毒舌点评:这代码,我看了都替你的海外用户着急。硬编码中文,你是想让外国用户看天书吗?

前端国际化的正确姿势

1. 使用i18next

// 正确姿势:使用i18next // i18n/index.js import i18n from 'i18next'; import { initReactI18next } from 'react-i18next'; import zh from './locales/zh.json'; import en from './locales/en.json'; i18n .use(initReactI18next) .init({ resources: { zh: { translation: zh }, en: { translation: en } }, lng: 'zh', fallbackLng: 'zh', interpolation: { escapeValue: false } }); export default i18n; // locales/zh.json { "login": { "title": "登录", "email": "请输入邮箱", "password": "请输入密码", "button": "登录", "noAccount": "还没有账号?", "register": "立即注册" } } // locales/en.json { "login": { "title": "Login", "email": "Please enter email", "password": "Please enter password", "button": "Login", "noAccount": "No account?", "register": "Register now" } } // 使用 import { useTranslation } from 'react-i18next'; function LoginForm() { const { t, i18n } = useTranslation(); const changeLanguage = (lng) => { i18n.changeLanguage(lng); }; return ( <form> <h1>{t('login.title')}</h1> <input placeholder={t('login.email')} /> <input placeholder={t('login.password')} type="password" /> <button>{t('login.button')}</button> <p> {t('login.noAccount')} <a href="/register">{t('login.register')}</a> </p> <button onClick={() => changeLanguage('zh')}>中文</button> <button onClick={() => changeLanguage('en')}>English</button> </form> ); } 

2. Vue3中使用vue-i18n

// 正确姿势:Vue3国际化 // i18n/index.js import { createI18n } from 'vue-i18n'; const messages = { zh: { message: { hello: '你好', welcome: '欢迎, {name}!' } }, en: { message: { hello: 'Hello', welcome: 'Welcome, {name}!' } } }; const i18n = createI18n({ locale: 'zh', fallbackLocale: 'en', messages }); export default i18n; // main.js import { createApp } from 'vue'; import App from './App.vue'; import i18n from './i18n'; const app = createApp(App); app.use(i18n); app.mount('#app'); // 使用 <template> <p>{{ $t('message.hello') }}</p> <p>{{ $t('message.welcome', { name: '张三' }) }}</p> <button @click="$i18n.locale = 'en'">English</button> </template> 

毒舌点评:早这么国际化,你的应用早就走向国际了。别告诉我你还只支持中文,那你还是趁早去开发国内市场吧。

实战技巧:国际化指南

1. 国际化最佳实践

  1. 提前规划:项目初期就考虑国际化
  2. 提取文本:所有用户可见文本都要提取
  3. 格式化:日期、数字、货币都要本地化
  4. RTL支持:阿拉伯语等从右到左的语言

2. 常用工具

  • i18next:React国际化
  • vue-i18n:Vue国际化
  • FormatJS:格式化库
  • react-intl:React国际化

最后想说的

国际化不是可选项,是必选项。别再只支持中文了——国际化一下,你的应用会走向更广阔的市场。

国际化就像学外语,一开始觉得麻烦,但学会后世界大门就打开了。别做井底之蛙,做世界公民。

Read more

AI 大模型落地系列|Eino ADK体系篇:你对 ChatModelAgent 有了解吗?

AI 大模型落地系列|Eino ADK体系篇:你对 ChatModelAgent 有了解吗?

声明:本文源于官方文档,重点参考 Eino ADK: ChatModelAgent、Eino ADK: 概述、Eino ADK: Agent 协作 分享一个很棒的AI技术博客,对AI感兴趣的朋友强烈推荐去看看http://blog.ZEEKLOG.net/jiangjunshow。 为什么很多人把 ChatModelAgent 想简单了?一文讲透 ReAct、Transfer、AgentAsTool 与 Middleware * 1. 为什么很多人会把 `ChatModelAgent` 想简单 * 2. `ChatModelAgent` 在 ADK 里到底是什么 * 3. 其内部本质是一个 `ReAct` 循环 * 没有 Tool 时会怎样 * 为什么还需要 `MaxIterations` * 4. 哪几组配置真正决定了行为 * `Name / Description`

【GitHub项目推荐--Moyin Creator(魔因漫创):AI影视生产级全流程创作工具】⭐⭐⭐

魔因漫创 是一款面向 AI 影视创作者的生产级工具。五大板块环环相扣,覆盖从剧本到成片的完整创作链路: 📝 剧本 → 🎭 角色 → 🌄 场景 → 🎬 导演 → ⭐ S级(Seedance 2.0) 每一步的产出自动流入下一步,无需手动搅合。支持多种主流 AI 大模型,适合短剧、动漫番剧、预告片等场景的批量化生产。 基础设置教程:https://www.bilibili.com/video/BV1FsZDBHExJ/?vd_source=802462c0708e775ce81f95b2e486f175 功能特性 ⭐ S级板块 — Seedance 2.0 多模态创作 SkyReels-V4 多模态创作 * 多镜头合并叙事视频生成:将多个分镜分组合并生成连贯叙事视频 * 支持 @Image / @Video / @Audio 多模态引用(角色参考图、场景图、首帧图自动收集)

DeerFlow 2.0:字节开源的超级 Agent 框架,让 AI 真正干活

DeerFlow 2.0:字节开源的超级 Agent 框架,让 AI 真正干活 作者:madprinter 日期:2026-03-24 项目地址:https://github.com/bytedance/deer-flow 项目介绍 DeerFlow(Deep Exploration and Efficient Research Flow)是字节跳动开源的一款超级 Agent 框架。2026 年 2 月 28 日,DeerFlow 2.0 正式发布后迅速登顶 GitHub Trending 榜首,目前已有近 40,000 颗星。 与传统的 AI 框架不同,