trans-sync-tool
v1.0.8
Published
Connect to yicat service and receive the latest translated segment in real-time.
Downloads
5
Maintainers
Readme
Description
Trans-Sync-Tool is a js plugin to help your translator to check translation text in your site real time.
You can add the code below to your project and the plugin will fetch or receive the newset segment from remote yicat server with a websocket channel, so they can translate and view text in same time.
Install
npm i trans-sync-tool -S
Usage
Init connection with a yicat config
import TransSyncTool from 'trans-sync-tool'
const yicatConfig = { email: '**@*.com', apiKey: '***', projectId: '***' }
const transSyncTool = new TransSyncTool(yicatConfig.email, yicatConfig.apiKey, yicatConfig.projectId, newMsgHandler)
Fetch all segments when page loaded.
// add the code to the component where we can switch the language locale
// run once when page load to get the latest messages
// for my project, zh-CN is not exist in remote server, because my project source language is chinese
if (userLanguage !== 'zh-CN') { // such as 'en-US'
// fetch all one time
transSyncTool.fetchAll(userLanguage).then(msgMap => {
if (msgMap) {
// set the whole messages to i18n or cave to your locale json properies.
i18n.setLocaleMessage(userLanguage, msgMap)
}
})
}
You can use i18n solution in your project and connect to yicat to fetch segments in where you manage your locale with i18n.
const transSyncTool = new TransSyncTool(yicatConfig.email, yicatConfig.apiKey, yicatConfig.projectId, (msg) => {
// handler to resolve new translated segment
// update the message for each segment
i18n._vm.messages[msg.tgtLan][msg.msgKey] = msg.tgtText // so we can view the text real-time
})
// attach it the i18n instance and use it anywhere
i18n.transSyncTool = transSyncTool
// add the code to the component where we can switch the language locale
// run once when page load to get the latest messages
// for my project, zh-CN is not exist in remote server, because my project source language is chinese
if (userLanguage !== 'zh-CN') { // such as 'en-US'
// fetch all one time
transSyncTool.fetchAll(userLanguage).then(msgMap => {
if (msgMap) {
// set the whole messages to i18n
i18n.setLocaleMessage(userLanguage, msgMap)
}
})
}
Trans-Sync-Tool works fine with another vue code tool i18n-yipicker(auto extract chinese text to a json file and send it to yicat-server) to get your localization work easier. I18n-Yipicker is not published to public, Contact YiCAT Team to get more if you need.
Let me know if you have any problem.
Visit YiCAT Page:
Tmxmall-YiCAT: https://www.yicat.vip
develop(nodejs16)
npm run dev
切换到master分支后编译和发布
publish
npm run build
npm publish --registry=https://registry.npmjs.org