Skip to content

Instantly share code, notes, and snippets.

@nothingrealhappen
Created October 5, 2020 08:10
Show Gist options
  • Save nothingrealhappen/d985e5f92805f10bfc57bf85800ad83e to your computer and use it in GitHub Desktop.
Save nothingrealhappen/d985e5f92805f10bfc57bf85800ad83e to your computer and use it in GitHub Desktop.
translate simplified chinese to traditional chinese
var _ = require('lodash')
var convert = require('chinese_convert')
const data = {
"message": {
"delete": "您要刪除此訪客嗎?"
},
"otherKeys": {
"supportNested": "支持嵌套的字段"
}
}
const mapValuesDeep = (v, callback) => (
_.isObject(v)
? _.mapValues(v, v => mapValuesDeep(v, callback))
: callback(v)
)
const result = mapValuesDeep(data, val => convert.cn2tw(val))
console.log('----------')
console.log(JSON.stringify(result))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment