前端国际化:别让你的应用只懂一种语言

前端国际化:别让你的应用只懂一种语言

毒舌时刻

这应用写得跟方言似的,出了本地就没人懂。

各位前端同行,咱们今天聊聊前端国际化。别告诉我你的应用还只有中文版本,那感觉就像在国际会议上只说方言——能说,但没人懂。

为什么你需要国际化

最近看到一个项目,想拓展海外市场,但所有文本都是硬编码在代码里的。我就想问:你是在做本地应用还是在做国际产品?

反面教材

// 反面教材:硬编码文本 function App() { return ( <div> <h1>欢迎来到我的网站</h1> <p>这是一个示例应用</p> <button>点击我</button> <div> <h2>产品列表</h2> <ul> <li>产品 1</li> <li>产品 2</li> <li>产品 3</li> </ul> </div> </div> ); } export default App; 

毒舌点评:这代码,就像在写日记,只有自己能看懂。

正确姿势

1. i18next

// 正确姿势:i18next // 1. 配置 // i18n.js import i18n from 'i18next'; import { initReactI18next } from 'react-i18next'; const resources = { zh: { translation: { welcome: '欢迎来到我的网站', description: '这是一个示例应用', button: '点击我', products: '产品列表', product1: '产品 1', product2: '产品 2', product3: '产品 3' } }, en: { translation: { welcome: 'Welcome to my website', description: 'This is a sample application', button: 'Click me', products: 'Product List', product1: 'Product 1', product2: 'Product 2', product3: 'Product 3' } } }; i18n .use(initReactI18next) .init({ resources, lng: 'zh', fallbackLng: 'en', interpolation: { escapeValue: false } }); export default i18n; // 2. 使用 // App.jsx import React from 'react'; import { useTranslation } from 'react-i18next'; function App() { const { t, i18n } = useTranslation(); const changeLanguage = (lng) => { i18n.changeLanguage(lng); }; return ( <div> <div> <button onClick={() => changeLanguage('zh')}>中文</button> <button onClick={() => changeLanguage('en')}>English</button> </div> <h1>{t('welcome')}</h1> <p>{t('description')}</p> <button>{t('button')}</button> <div> <h2>{t('products')}</h2> <ul> <li>{t('product1')}</li> <li>{t('product2')}</li> <li>{t('product3')}</li> </ul> </div> </div> ); } export default App; // 3. 入口文件 // index.js import React from 'react'; import ReactDOM from 'react-dom'; import App from './App'; import './i18n'; ReactDOM.render( <React.StrictMode> <App /> </React.StrictMode>, document.getElementById('root') ); 

2. react-intl

// 正确姿势:react-intl // 1. 配置 // App.jsx import React from 'react'; import { IntlProvider, FormattedMessage } from 'react-intl'; const zhMessages = { welcome: '欢迎来到我的网站', description: '这是一个示例应用', button: '点击我', products: '产品列表', product1: '产品 1', product2: '产品 2', product3: '产品 3' }; const enMessages = { welcome: 'Welcome to my website', description: 'This is a sample application', button: 'Click me', products: 'Product List', product1: 'Product 1', product2: 'Product 2', product3: 'Product 3' }; function App() { const [locale, setLocale] = React.useState('zh'); const messages = locale === 'zh' ? zhMessages : enMessages; return ( <IntlProvider locale={locale} messages={messages}> <div> <div> <button onClick={() => setLocale('zh')}>中文</button> <button onClick={() => setLocale('en')}>English</button> </div> <h1><FormattedMessage /></h1> <p><FormattedMessage /></p> <button><FormattedMessage /></button> <div> <h2><FormattedMessage /></h2> <ul> <li><FormattedMessage /></li> <li><FormattedMessage /></li> <li><FormattedMessage /></li> </ul> </div> </div> </IntlProvider> ); } export default App; 

3. 日期和数字格式化

// 正确姿势:日期和数字格式化 import React from 'react'; import { useTranslation } from 'react-i18next'; function FormattingExample() { const { t, i18n } = useTranslation(); const formatDate = (date) => { return new Intl.DateTimeFormat(i18n.language).format(date); }; const formatNumber = (number) => { return new Intl.NumberFormat(i18n.language).format(number); }; return ( <div> <p>{t('currentDate')}: {formatDate(new Date())}</p> <p>{t('price')}: {formatNumber(12345.67)}</p> </div> ); } export default FormattingExample; 

毒舌点评:这才叫国际化,让你的应用在全球范围内都能被理解。

Read more

VSCode自定义Copilot Agent与Awesome Agent

VSCode自定义Copilot Agent与Awesome Agent

本文将介绍如何在VSCode中创建自定义的Agent,以及哪里可以获取到现有的Agent模板 当我们在VSCode中使用Copilot时,可以选择以下几种模式。 Ask, Edit, Agent, 以及在2025年末时我们可以使用的全新的Plan模式。 不过除此之外,其实我们还有办法自定义属于自己的Agent。 选择右下角Agent菜单,选择Configure Custom Agents... 如选择.github\agents 则会在本工作区域中生成该路径并创建一个指定命名的agent.md文件 如果选择User Data则是会创建全局的Agent模板 在vscode中,也可以直接在文件中通过Configure Tools轻松配置所需要使用的tools,非常方便。 然后我们便可以在copilot中使用自己的Agent了. 当然,自己编写一个相对复杂的agent模板比较耗时,而awesome-copilot项目为我们提供了许多的模板,当然不止是agent,也提供了丰富的提示词模板(prompt)和指导词模板(instructions),以及

VsCode远程连接服务器后安装Github Copilot无法使用

VsCode远程连接服务器后安装Github Copilot无法使用

VsCode远程连接服务器后安装Github Copilot无法使用 1.在Vscode的settings中搜索Extension Kind,如图所示: 2.点击Edit in settings.json,添加如下代码: "remote.extensionKind":{"GitHub.copilot":["ui"],"GitHub.copilot-chat":["ui"],} remote.extensionKind 的作用 这是 VS Code 的远程开发配置项,用于控制扩展在远程环境(如 SSH、容器、WSL)中的运行位置。可选值: “ui”:扩展在本地客户端运行 “workspace”:扩展在远程服务器运行 这两个扩展始终在 本地客户端运行,

低代码AI化:是否正在重构开发行业格局?

低代码AI化:是否正在重构开发行业格局?

当低代码遇上AI,不再是简单的“拖拽+模板”拼凑,而是技术逻辑与业务场景的深度重构。JNPF依托AI能力,将表单、字段、咨询、流程四大核心环节智能化升级,让“不懂代码也能做开发”从噱头落地为现实。这是否意味着,低代码AI化正悄然颠覆整个开发行业的底层逻辑? 一、技术底层重构:从“工具拼接”到“原生智能”         传统低代码的核心局限,在于架构层面的“伪智能”。多数平台仅将AI作为附加插件,通过API调用实现表单生成、字段推荐等基础功能,本质上仍是“模板填充+关键词匹配”的逻辑,既无法深度适配个性化业务场景,也难以突破数据孤岛与功能壁垒。         而JNPF实现的是AI与低代码底层架构的深度耦合,以“原生智能”重构开发链路: * AI表单:摒弃传统模板套取模式,基于NLP语义解析技术,直接将自然语言描述转化为标准化表单。例如输入“客户售后工单系统:包含工单编号、客户信息、问题类型、处理进度、回访记录,支持状态流转与权限管控”

Whisper 模型本地化部署:全版本下载链接与离线环境搭建教程

Whisper 模型本地化部署指南 一、模型版本与下载 Whisper 提供多种规模版本,可通过以下官方渠道获取: 1. GitHub 仓库 https://github.com/openai/whisper 包含最新代码、预训练权重和文档 * tiny.en / tiny * base.en / base * small.en / small * medium.en / medium * large-v2 (最新大模型) Hugging Face 模型库 所有版本下载路径: https://huggingface.co/openai/whisper-{version}/tree/main 替换 {version} 为具体型号: 二、离线环境搭建教程 准备工作 1.