zhangfisher / voerka-i18n Goto Github PK
View Code? Open in Web Editor NEWNodejs/Vue/React International solutions
Home Page: https://zhangfisher.github.io/voerka-i18n/
License: MIT License
Nodejs/Vue/React International solutions
Home Page: https://zhangfisher.github.io/voerka-i18n/
License: MIT License
我这样写注释// const aaa=t("扫码")
然后执行voerkai18n extract后,这段注释文字也被提取了
vue 文件中引用了 constant.ts ,如 export const test = t("需要翻译的文字")
vue 文件中:
import test from constant.ts
提取的翻译文件中包含 "需要翻译的文字":{zh:"需要翻译的文字",en:"Text that needs translation"}
但是 test 的文本内容不跟随激活语言的变化而变化,一直都是 "需要翻译的文字"
VoerkaI18n 3.0新特性征集:
即一个词在不同的上下文场景中需要翻译为不同的词。
现有的cli
命令需要输入的参数较多,不容易记住,拟引入交互式提示功能。
通过交互提示输入各种参数,减少记忆负担。
详见Mixed-cli
VoerkaI18n
支持动态语言包补丁功能,也可以很容易扩展在线修改语言词条的功能,见这里
拟提供开箱即用的解决方案,让用户直接在界面上进行翻译修改。
由于不同语言的长度差异很大,当多语言的切换往往会导致界面布局混乱,所以增加一个特性
当切换语言时在body
上自动添加data-language='<当前语言>'
的属性,这样开发时就可以为不同的语言添加定制样式
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@voerkai18%2fcli - Not found
忽略 发现是官网文章写错了
https://zhangfisher.github.io/voerka-i18n/zh/guide/intro/install.html#voerkai18-cli
eggjs项目,执行命令voerkai18n init
初始化报错
PS E:\nodejs-dev\dataWish_serve\app> voerkai18n init
工程目录:E:\nodejs-dev\dataWish_serve
语言目录:languages
node:internal/errors:464
ErrorCaptureStackTrace(err);
^
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received null
at new NodeError (node:internal/errors:371:5)
at validateString (node:internal/validators:119:11)
at Object.join (node:path:429:7)
at getCurrentPackageJson (C:\Users\vobea\AppData\Local\Yarn\Data\global\node_modules\@voerkai18n\utils\index.js:212:32)
at Object.initializer (C:\Users\vobea\AppData\Local\Yarn\Data\global\node_modules\@voerkai18n\cli\init.command.js:87:32)
at Command.<anonymous> (C:\Users\vobea\AppData\Local\Yarn\Data\global\node_modules\@voerkai18n\cli\init.command.js:204:27)
at Command.listener [as _actionHandler] (C:\Users\vobea\AppData\Local\Yarn\Data\global\node_modules\@voerkai18n\cli\node_modules\commander\lib\command.js:482:17)
at C:\Users\vobea\AppData\Local\Yarn\Data\global\node_modules\@voerkai18n\cli\node_modules\commander\lib\command.js:1283:65
at C:\Users\vobea\AppData\Local\Yarn\Data\global\node_modules\@voerkai18n\cli\node_modules\commander\lib\command.js:1174:33
at async Command.parseAsync (C:\Users\vobea\AppData\Local\Yarn\Data\global\node_modules\@voerkai18n\cli\node_modules\commander\lib\command.js:935:5) {
code: 'ERR_INVALID_ARG_TYPE'
}
RT
yarn global v1.22.21
warning package.json: No license field
[1/4] Resolving packages...
error Error: certificate has expired
at TLSSocket.onConnectSecure (node:_tls_wrap:1674:34)
at TLSSocket.emit (node:events:518:28)
at TLSSocket._finishInit (node:_tls_wrap:1085:8)
at ssl.onhandshakedone (node:_tls_wrap:871:12)
info Visit https://yarnpkg.com/en/docs/cli/global for documentation about this command.
你好,按照开发示例在babel.config.js
中这么配置:
const i18nPlugin = require("@voerkai18n/babel")
module.expors = {
plugins: [
[
i18nPlugin,
{
// 可选,指定语言文件存放的目录,即保存编译后的语言文件的文件夹
// 可以指定相对路径,也可以指定绝对路径
// location:"",
autoImport:"#/languages"
}
]
]
}
提示
请问这种情况是我这里的autoImport配置错了吗?这里配置了路径也不行。
另外手动引入 t
也报错,demo是基于vue2做的。
方便邮件或者微信沟通吗?群二维码已经过期了。
1、历史项目改造:支持脚本或插件一键替换代码中的中文 t(‘中文’)
2、eslint插件支持:如存在中文未国际化则报错不让提交
3、支持翻译资源文件从服务端获取
使用npm install --g @voerkai18n/cli下载脚手架之后,运行voerkai18n init命令报错ReferenceError: VoerkaI18nScope is not defined
node 环境:v16.14.0
React项目(非create-react-app创建,自定义webpack搭建项目):版本17.0.2
未使用TS,默认所有的文件名都是jsx或者js,以及less进行样式控制
所有默认的源码路径位于:根目录 ./src 目录下,但是html模板文件位于根目录 ./public下 ,无其他异常配置
当前执行 init操作后,会自动在src目录下生成language文件夹,但是,执行extract命令没有任何作用,没有扫描和提取到任何中文字条,这是怎么回事呢?
项目结构如下:
[图片]
基于原始的代码实现无法获取到数据更改为这样才能获取到内容.修改为cli 模板生成代码截图如上,代码如下:
const messages = {
{{each languages}}{{if $value.name == defaultLanguage}}'{{defaultLanguage}}' : defaultMessages{{if $index !== languages.length - 1}},{{/if}}
{{else if $value.name == activeLanguage}}{{if defaultLanguage !== activeLanguage}}'{{activeLanguage}}':defaultFormatters{{/if}}{{if $index !== languages.length - 1}},{{/if}}
{{else}}'{{$value.name}}' : async ()=> (await import("./{{$value.name}}")).default{{if $index !== languages.length - 1}},{{'\n\t'}}{{/if}}{{/if}}{{/each}}
}
const formatters = {
{{each languages}}{{if $value.name == defaultLanguage}}'{{defaultLanguage}}' : defaultFormatters{{if $index !== languages.length - 1}},{{/if}}
{{else if $value.name == activeLanguage}}{{if defaultLanguage !== activeLanguage}}'{{activeLanguage}}':activeMessages{{/if}}{{if $index !== languages.length - 1}},{{/if}}
{{else}}'{{$value.name}}' : async ()=> (await import("./formatters/{{$value.name}}")).default{{if $index !== languages.length - 1}},{{'\n\t'}}{{/if}}{{/if}}{{/each}}
}
对于已经翻译了的复数,再次执行自动翻译,会覆盖以前的内容
原内容如:
"周{}": {
"zh": ["0", "周一", "周二", "周三", "周四", "周五", "周六", "周日"],
"en": ["0", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
"$files": []
},
自动翻译:voerkai18n translate --mode auto
翻译之后:
"周{}": {
"zh": ["0", "周一", "周二", "周三", "周四", "周五", "周六", "周日"],
"en": "Zhou {}",
"$files": []
},
已经翻译的英文数组被覆盖了
能修复下文档样式吗? 阅读体验很不友好,麻烦你了
Hello,
url: https://zhangfisher.github.io/voerka-i18n/#/
I really like the blue github referrer at the top of your site. Can you share the design codes with me?
很好的工具,大佬,有微信群吗,反馈问题沟通会方便点
按照文档说明 增加并配置了@voerkai18n/vite插件 , 但是在vue3代码中 如果脚本是下列格式
<script setup>
console.log(t("Welcome to VoerkaI18n"))
</script>
会提示错误
ReferenceError: t is not defined
@voerkai18n/vite插件的作用不是自动引入t函数么 , 还是需要每次调用手动引入 ?
我使用的依赖版本 :
"vue": "^3.4.21",
"vite": "^5.1.6",
"@vitejs/plugin-vue": "^5.0.4",
"@voerkai18n/runtime": "^2.1.9",
"@voerkai18n/vite": "^2.1.9",
"@voerkai18n/vue": "^2.1.9",
命令执行演示
❯ voerkai18n extract
/usr/bin/env: “node\r”: 没有那个文件或目录
查看node_modules/@voerkai18n/cli/index.js
文件是crlf换行符
linux系统中Shebang
会读取执行文件第一行,crlf
的换行符会在行末多出一个\r
字符,导致查找执行文件从node
变为了查找node\r
,从报错提示中也能证明这一点
将cli文件的换行符改为lf
开发影响:因为crlf换行符是windows格式,如果改为lf可能需要同时修改git配置 https://stackoverflow.com/questions/1967370/git-replacing-lf-with-crlf
运行影响:nodejs脚本本身能够支持crlf和lf格式,在windows上执行js脚本,是先调用bat或ps1载入node程序后,再执行js脚本,过程中没有换行符影响
根目录有package.json的前提,没有就npm ini 初始化一个
node:internal/errors:478
ErrorCaptureStackTrace(err);
^
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received null
解决办法:根目录新建目录src
开发环境:
win10 64位
node 14.21.3
项目环境:
vue2
报错:
Extract translate text has occur error from views\infoManage\components\QualificationView.vue:/\<(?<tagName>\w+)(.*?)(?<i18nKey>{attrName}\s*\=\s*)([\"\'']{1})(?<text>.*?)(\4){1}\s*(.*?)(\>|\/\>)/gm. TypeError: content.replaceAll is not a function
at D:\Program Files\nvm\v14.21.3\node_modules\@voerkai18n\cli\extract.plugin.js:49:35
at Array.forEach (<anonymous>)
at D:\Program Files\nvm\v14.21.3\node_modules\@voerkai18n\cli\extract.plugin.js:48:21
at Array.forEach (<anonymous>)
at removeComments (D:\Program Files\nvm\v14.21.3\node_modules\@voerkai18n\cli\extract.plugin.js:46:35)
at extractTranslateTextUseRegexp (D:\Program Files\nvm\v14.21.3\node_modules\@voerkai18n\cli\extract.plugin.js:106:15)
at D:\Program Files\nvm\v14.21.3\node_modules\@voerkai18n\cli\extract.plugin.js:211:28
at Array.reduce (<anonymous>)
at getTranslateTexts (D:\Program Files\nvm\v14.21.3\node_modules\@voerkai18n\cli\extract.plugin.js:201:26)
at Transform._transform (D:\Program Files\nvm\v14.21.3\node_modules\@voerkai18n\cli\extract.plugin.js:412:27)
看了下default.json
是空。
namespaces在languages/settings.json下配置并未生效,阅读源码后发现namespaces读取的是package.json下的配置
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.