UNPKG

tencentcloud-edgeone-migration-nodejs-v2

Version:

tencentcloud cdn config copy to edgeone

31 lines (26 loc) 613 B
const hashString = require("hash-string"); const i18n = require("i18n"); const argv = process.argv.slice(2)[0]; const lang = argv || "zh"; i18n.configure({ locales: ["en", "zh"], directory: __dirname + "/locales", defaultLocale: "zh", objectNotation: true, register: global, }); i18n.setLocale(lang); function genHashKey(zhStr) { const key = `k_${`0000${hashString(zhStr.replace(/\s+/g, "")).toString( 36 )}`.slice(-7)}`; return key; } function t(zhStr, arg) { const hasKey = genHashKey(zhStr); return i18n.__(hasKey, arg).replace(/"/g, '"'); } module.exports = { t, lang, };