Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
i18n-auto-react
Advanced tools
Readme
npm install i18n-auto-react
# or
yarn add i18n-auto-react
# or
pnpm install i18n-auto-react
npx i18n init
初始化配置 i18n.config.js
i18n.config.js
配置appId和密钥npm run i18n:translate
扫描文件中的中文并翻译成语言包npm run i18n:genExport
生成语言包导出文件module.exports = {
module: {
rules: [
{
test: /\.(js|jsx|ts|tsx)$/,
loader: 'i18n-auto-react/webpack',
options: require('../i18n.config.js') // 路径以实际情况为准
},
// ...other loader
]
}
}
// vite.config.js
import { i18nAutoPlugin } from 'i18n-auto-react/vite'
export default defineConfig({
plugins: [
// ...other plugin
i18nAutoPlugin()
]
})
翻译函数
调用aa, bb
),或者本来就有翻译函数包裹 (cc
) 的会忽略翻译转换前
import React from 'react'
import { i18n as _i18n } from 'i18n-auto-react'
let world = '世界'
// i18n-disable-next
let aa = '我是被忽略翻译的中文'
let bb = '我也是被忽略翻译的中文' // i18n-disable
let cc = _i18n('我也也是被忽略翻译的中文')
export default function App() {
return (
<div>
<h3 title="花飘万家雪">你好{world}</h3>
<h3>{aa + bb + cc}</h3>
</div>
)
}
转换后
import React from 'react';
// 如当前页面有需要翻译的中文时,会自动引入
import { i18n as _i18n } from "i18n-auto-react";
let world = _i18n("c086b3008aca0efa8f2ded065d6afb50");
// i18n-disable-next
let aa = '我是被忽略翻译的中文';
let bb = '我也是被忽略翻译的中文'; // i18n-disable
let cc = _i18n('我也也是被忽略翻译的中文')
export default function App() {
return (
<div>
<h3 title={_i18n("29fd4016d2b8d06be750109579b7301e")}>
{_i18n("7eca689f0d3389d9dea66ae112e5cfd7")}{world}
</h3>
<h3>{aa + bb + cc}</h3>
</div>
)
}
import React from 'react'
import { changeLanguage, currentLanguage } from 'i18n-auto-react'
export default function App() {
return (
<div>
<button
onClick={() => {
// 获取当前语言
let currLng = currentLanguage()
// 切换语言
changeLanguage(currLng == 'zh' ? 'en' : 'zh')
}}
>
切换语言
</button>
</div>
)
}
FAQs
基于百度翻译API服务的自动翻译插件
The npm package i18n-auto-react receives a total of 2 weekly downloads. As such, i18n-auto-react popularity was classified as not popular.
We found that i18n-auto-react demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.