xshell 0.0.18 → 0.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/file.js +1 -2
- package/file.js.map +1 -1
- package/i18n/README.md +283 -0
- package/i18n/dict.d.ts +30 -0
- package/i18n/dict.js +34 -0
- package/i18n/dict.js.map +1 -0
- package/i18n/i18n-scan.d.ts +2 -0
- package/i18n/i18n-scan.js +21 -0
- package/i18n/i18n-scan.js.map +1 -0
- package/i18n/i18n.ico +0 -0
- package/i18n/index.d.ts +65 -0
- package/i18n/index.js +118 -0
- package/i18n/index.js.map +1 -0
- package/i18n/rwdict.d.ts +42 -0
- package/i18n/rwdict.js +110 -0
- package/i18n/rwdict.js.map +1 -0
- package/i18n/scanner/checker.d.ts +5 -0
- package/i18n/scanner/checker.js +73 -0
- package/i18n/scanner/checker.js.map +1 -0
- package/i18n/scanner/index.d.ts +52 -0
- package/i18n/scanner/index.js +319 -0
- package/i18n/scanner/index.js.map +1 -0
- package/i18n/scanner/parser.d.ts +3 -0
- package/i18n/scanner/parser.js +154 -0
- package/i18n/scanner/parser.js.map +1 -0
- package/i18n/utils.d.ts +1 -0
- package/i18n/utils.js +14 -0
- package/i18n/utils.js.map +1 -0
- package/net.js +2 -4
- package/net.js.map +1 -1
- package/package.json +37 -10
- package/repl.js +4 -8
- package/repl.js.map +1 -1
- package/server.d.ts +1 -0
- package/server.js +2 -3
- package/server.js.map +1 -1
- package/ufs.js +3 -3
- package/ufs.js.map +1 -1
- package/tsconfig.json +0 -68
package/file.js
CHANGED
|
@@ -188,10 +188,9 @@ async function frename(fp, fp_, { fpd, print = true, overwrite = true } = {}) {
|
|
|
188
188
|
}
|
|
189
189
|
exports.frename = frename;
|
|
190
190
|
async function fmkdir(fpd, options = {}) {
|
|
191
|
-
var _a;
|
|
192
191
|
if (!upath_1.default.isAbsolute(fpd))
|
|
193
192
|
throw new Error('fpd must be absolute path');
|
|
194
|
-
|
|
193
|
+
options.print ?? (options.print = true);
|
|
195
194
|
if (fpd.fexists)
|
|
196
195
|
if (fpd.is_dir) {
|
|
197
196
|
if (options.print && !options.suppress_existence)
|
package/file.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.js","sourceRoot":"","sources":["file.ts"],"names":[],"mappings":";;;;AAAA,2BAA2C;AAG3C,+DAAwB;AACxB,yEAA8B;AAC9B,uDAA+C;AAC/C,qEAA0B;AAC1B,iEAA2B;AAE3B,4EAAsC;AAGtC,+DAAuB;AAWd,cAXF,eAAG,CAWE;AAJZ,2CAAqC;AACrC,mCAAgC;AAChC,qDAAqB;AAOrB,SAAgB,UAAU;IACtB,OAAO,WAAG,GAAG,MAAM,CAAC,MAAM,CACtB,eAAG,CAAC,kBAAkB,CAClB,IAAI,eAAG,CAAC,MAAM,EAAE,CACnB,EACD,EAAE,IAAI,EAAE,eAAI,CAAC,IAAI,CAAC,IAAI,CAAC,eAAI,CAAC,EAAE,CACjC,CAAA;AACL,CAAC;AAPD,gCAOC;AAQM,KAAK,UAAU,KAAK,CAAE,EAAU,EAAE,EACrC,GAAG,EACH,QAAQ,GAAG,OAAO,EAClB,KAAK,GAAG,IAAI,KAIQ,EAAG;IAEvB,IAAI,GAAG;QACH,EAAE,GAAG,eAAI,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;SACtB,IAAI,CAAC,eAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAA;IAE3E,IAAI,KAAK;QACL,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,CAAC,CAAA;IAE9B,MAAM,MAAM,GAAG,MAAM,aAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;IAErC,IAAI,QAAQ,KAAK,QAAQ;QACrB,OAAO,MAAM,CAAA;IAEjB,IAAI,QAAQ,KAAK,OAAO;QACpB,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM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CAAC,kBAAkB,EAAE,UAAU,CAAC,EAAE,CAAA;IAC9E,IAAI,CAAC,MAAM,CAAC,OAAO;QACf,MAAM,KAAK,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;IAE3B,MAAM,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;AAC1B,CAAC;AAlBD,wBAkBC","sourcesContent":["import { promises as fsp, watch } from 'fs'\nimport type fs from 'fs'\n\nimport path from 'upath'\nimport iconv from 'iconv-lite'\nimport { readdirAsync } from 'readdir-enhanced'\nimport fse from 'fs-extra'\nimport rimraf from 'rimraf'\n\nimport debounce from 'lodash/debounce'\n\n\nimport MFS from 'memfs'\ndeclare module 'memfs' {\n interface IFs {\n join: typeof path.join\n }\n}\n\nimport { to_json } from './prototype'\nimport { dedent } from './utils'\nexport * from './ufs'\n\nexport { MFS }\n\nexport type Encoding = 'utf-8' | 'gb18030' | 'shift-jis' | 'binary'\n\n\nexport function create_mfs () {\n return mfs = Object.assign(\n MFS.createFsFromVolume(\n new MFS.Volume()\n ), \n { join: path.join.bind(path) }\n )\n}\n\nexport let mfs: MFS.IFs & { join: typeof path.join }\n\n\nexport async function fread (fp: string): Promise<string>\nexport async function fread (fp: string, { dir, encoding, print }?: { dir?: string, encoding: 'binary', print?: boolean }): Promise<Buffer>\nexport async function fread (fp: string, { dir, encoding, print }?: { dir?: string, encoding?: Encoding | 'auto', print?: boolean }): Promise<string>\nexport async function fread (fp: string, {\n dir, \n encoding = 'utf-8', \n print = true\n}: {\n dir?: string\n encoding?: Encoding | 'auto'\n print?: boolean } = { }\n) {\n if (dir)\n fp = path.join(dir, fp)\n else if (!path.isAbsolute(fp))\n throw new Error('fp must be absolute path, or pass in \"dir\" parameter')\n \n if (print)\n console.log(`read: ${fp}`)\n \n const buffer = await fsp.readFile(fp)\n \n if (encoding === 'binary')\n return buffer\n \n if (encoding === 'utf-8')\n return buffer.toString('utf8')\n \n if (encoding === 'auto') {\n const { detect } = await import('chardet')\n encoding = detect(buffer) as any\n if (print)\n console.log(`${fp} probably has encoding: ${encoding.toLowerCase()}`)\n }\n \n return iconv.decode(buffer, encoding)\n}\n\nexport async function fread_lines (fp: string, options: { dir?: string, encoding?: Exclude<Encoding, 'binary'> | 'auto', print?: boolean } = { }) {\n return (await fread(fp, options))\n .split_lines()\n}\n\nexport async function fread_json <T = any> (fp: string, options: { dir?: string, encoding?: Encoding, print?: boolean } = { }): Promise<T> {\n return JSON.parse(\n await fread(fp, options)\n )\n}\n\n\nexport async function fwrite (fp: string, data: Buffer, options?: { dir?: string, print?: boolean }): Promise<void>\nexport async function fwrite (fp: string, data: any, options?: { dir?: string, encoding?: Encoding, print?: boolean }): Promise<void>\nexport async function fwrite (fp: string, data: any, { dir, encoding = 'utf-8', print = true }: { dir?: string, encoding?: Encoding, print?: boolean } = { }) {\n if (dir)\n fp = path.join(dir, fp)\n else if (!path.isAbsolute(fp))\n throw new Error('fp must be absolute path, or pass in \"dir\" parameter')\n \n if (print)\n console.log('write:', fp)\n \n if (encoding === 'gb18030')\n data = iconv.encode(data, encoding)\n \n if (!Buffer.isBuffer(data) && typeof data !== 'string')\n data = to_json(data)\n \n await fsp.writeFile(fp, data)\n}\n\nexport async function fappend (fp: string, data: any, { dir, print = true }: { dir?: string, print?: boolean } = { }) {\n if (dir)\n fp = path.join(dir, fp)\n else if (!path.isAbsolute(fp))\n throw new Error('fp must be absolute path, or pass in \"dir\" parameter')\n \n if (print)\n console.log('append:', fp)\n \n if (!Buffer.isBuffer(data) && typeof data !== 'string')\n throw new Error('data is not Buffer or string')\n \n await fsp.appendFile(fp, data)\n}\n\n\n/**\n - fpd: absolute path of directory\n - optoins?:\n - deep?: `false` recursively\n - absolute?: `false` return absolute path\n - print?: `true`\n - filter?: `true` RegExp | (fp: string) => any\n*/\nexport async function flist (fpd: string, {\n filter, \n deep = false, \n absolute = false,\n print = true\n}: {\n filter?: RegExp | ((fp: string) => any)\n deep?: boolean\n absolute?: boolean\n print?: boolean\n} = { }) {\n if (!path.isAbsolute(fpd))\n throw new Error('fpd must be absolute path')\n \n let fps = await readdirAsync(fpd, {\n ...(absolute ? { basePath: fpd } : { }),\n deep,\n stats: false,\n })\n \n fps = fps.map( fp => {\n fp = path.normalize(fp)\n if (print)\n console.log(fp)\n return fp\n })\n \n if (filter instanceof RegExp)\n return fps.filter( fp => filter.test(fp))\n else if (filter)\n return fps.filter(filter)\n else\n return fps\n}\n\n\n/** delete file or directory (use rimraf to delete directory fast) \n - fp: path\n - options?:\n - print?: `true` (effective only delete single file)\n*/\nexport async function fdelete (fp: string, { print = true, fast = false }: { print?: boolean, fast?: boolean } = { }) {\n if (fp.length < 6) throw new Error(`${fp} too short`)\n if (!path.isAbsolute(fp))\n throw new Error('fpd must be absolute path')\n \n if (fp.is_dir) {\n if (print)\n console.log(`delete directory: ${fp}`.red)\n await new Promise<void>((resolve, reject) => {\n rimraf(fp, { glob: false, disableGlob: true }, error => {\n if (error)\n reject(error)\n else\n resolve()\n })\n })\n } else {\n if (print)\n console.log('delete:', fp)\n await fsp.unlink(fp)\n }\n}\n\n\n/** copy file or direcotry\n - src: src file/directory absolute path\n - dst: dst file/directory absolute path\n @example\n fcopy('d:/temp/camera/', 'd:/camera/')\n*/\nexport async function fcopy (src: string, dst: string, {\n print = true,\n overwrite = true,\n}: {\n print?: boolean\n overwrite?: boolean\n} = { }) {\n if (src.endsWith('/') !== dst.endsWith('/')) throw new Error('src and dst must be both file path or directory path')\n if (!path.isAbsolute(src) || !path.isAbsolute(dst)) throw new Error('src and dst must be absolute path')\n if (print)\n console.log(`copy: ${src} → ${dst}`)\n await fse.copy(src, dst, { overwrite, errorOnExist: true })\n}\n\n\n/** move file or direcotry\n - src: src file/directory absolute path\n - dst: dst file/directory absolute path\n @example\n fmove('d:/temp/camera/', 'd:/camera/')\n*/\nexport async function fmove (src: string, dst: string, {\n overwrite = false,\n print = true\n}: {\n overwrite?: boolean\n print?: boolean\n} = { }) {\n if (src.endsWith('/') !== dst.endsWith('/')) throw new Error('src and dst must be both file path or directory path')\n if (!path.isAbsolute(src) || !path.isAbsolute(dst)) throw new Error('src and dst must be absolute path')\n if (print)\n console.log(`move: ${src} → ${dst}`)\n await fse.move(src, dst, { overwrite })\n}\n\n\n/** rename file \n - fp: current filename/path\n - fp_: new filename/path\n - options?:\n - fpd?: fp and fp_ is in same directory\n - print?: `true`\n - overwrite?: `true` better performance without check\n */\nexport async function frename (\n fp: string, \n fp_: string,\n {\n fpd,\n print = true,\n overwrite = true\n }: {\n fpd?: string\n print?: boolean\n overwrite?: boolean\n } = { }\n) {\n if (fpd) {\n fp = path.join(fpd, fp)\n fp_ = path.join(fpd, fp_)\n } else if (!path.isAbsolute(fp) || !path.isAbsolute(fp_))\n throw new Error('fp and fp_ must be absolute path')\n \n if (print)\n console.log('rename:', fp, '→', fp_)\n \n if (!overwrite && fp_.fexists)\n throw new Error(`file already exists:${fp_}`)\n \n await fsp.rename(fp, fp_)\n}\n\n\nexport async function fmkdir (fpd: string, options: fs.MakeDirectoryOptions & { print?: boolean, suppress_existence?: boolean } = { }) {\n if (!path.isAbsolute(fpd))\n throw new Error('fpd must be absolute path')\n \n options.print ??= true\n \n if (fpd.fexists)\n if (fpd.is_dir) {\n if (options.print && !options.suppress_existence)\n console.log('directory already exists:', fpd)\n return\n } else throw new Error(`file with same name already exists, cannot create directory: ${fpd}`)\n else if (options.print)\n console.log('create new directory:', fpd)\n \n await fsp.mkdir(fpd, { recursive: true })\n}\n\n\n/** - link: can be file path or directory path */\nexport async function flink (\n fp_real: string, \n fp_link: string, \n {\n junction = false,\n print = true \n }: { \n junction?: boolean\n print?: boolean\n} = { }) {\n if (!path.isAbsolute(fp_real) || !path.isAbsolute(fp_link))\n throw new Error('fpd must be absolute path')\n \n if (fp_link.fexists)\n if (fp_link.is_dir)\n fp_link = path.join(fp_link, fp_real.fname)\n else if ( (await fsp.lstat(fp_link)).isSymbolicLink() ) {\n console.log('link already exists:', fp_link)\n return\n } else\n throw new Error('file with same name already exists, cannot create new link')\n \n \n if (print)\n console.log(`source file ${fp_real} linked to ${fp_link}`)\n \n if (junction)\n fsp.symlink(fp_real, fp_link, 'junction')\n else\n fsp.symlink(fp_real, fp_link, fp_real.is_dir ? 'dir' : 'file')\n}\n\n\nexport function link_shortcut (target: string, name: string, { args }: { args?: string[] } = { }) {\n const cmd = dedent`\n $wsh_shell = New-Object -comObject WScript.Shell\n $shortcut = $wsh_shell.CreateShortcut(\"d:/links/#{name}.lnk\")\n $shortcut.TargetPath = '${target}'\n $shortcut.Arguments = \"${args || ''}\"\n $shortcut.WorkingDirectory = '${target.fdir}'\n ${ target.is_dir ? '$shortcut.IconLocation = \"%SystemRoot%\\\\System32\\\\SHELL32.dll,3\"' : '' }\n $shortcut.Save()\n `\n console.log(cmd)\n // await psh(cmd)\n}\n\n\nexport let fwatchers: Record<string, fs.FSWatcher> = { }\n\n/**\n - fp: path of file or directory\n - callback: called when modified\n - exec: call callback when watch is executed\n save fs.FSWatcher in watchers, subsequent call will auto close existing watcher for the same fp\n \n https://nodejs.org/dist/latest-v15.x/docs/api/fs.html#fs_fs_watch_filename_options_listener \n The listener callback gets two arguments (event, filename). \n event is either 'rename' or 'change', and filename is the name of the file which triggered the event.\n On most platforms, 'rename' is emitted whenever a filename appears or disappears in the directory.\n \n The listener callback is attached to the 'change' event fired by fs.FSWatcher, but it is not the same thing as the 'change' value of event. \n \n*/\nexport async function fwatch (\n fp: string, \n onchange: (event: string, filename: string) => any,\n { exec = true }: { exec?: boolean } = { }\n) {\n if (!path.isAbsolute(fp)) throw new Error('fp must be absolute path')\n \n const _watcher = fwatchers[fp]\n if (_watcher)\n _watcher.close()\n \n if (exec)\n await onchange('change', fp)\n \n const debounced_onchange = debounce((event, filename) => {\n console.log(`file changed (${event}): ${filename}`)\n onchange(event, path.normalize(filename))\n }, 500, { leading: false, trailing: true })\n const watcher = watch(fp, debounced_onchange)\n watcher.on('error', error => { console.error(error) })\n return fwatchers[fp] = watcher\n}\n\n\n/** open a file and replace certain pattern */\nexport async function freplace (fp: string, pattern: string | RegExp, replacement: string) {\n await fwrite(\n fp,\n (await fread(fp))\n .replaceAll(pattern, replacement)\n )\n}\n\n/** convert file encoding to UTF-8\n - fp: file absolute path\n - options?:\n - dryrun?: `true`\n - encoding?: `'auto'`\n*/\nexport async function f2utf8 (fp: string, {\n dryrun = true,\n encoding = 'auto',\n}: {\n dryrun?: boolean\n encoding?: Encoding | 'auto'\n} = { }) {\n const text = await fread(fp, { encoding })\n if (dryrun) {\n console.log(text.slice(0, 10000))\n return\n }\n \n const fp_bak = `${fp.fdir}${fp.fname.replace(/(.*?)(\\.[^.]+)?$/, '$1.bak$2')}`\n if (!fp_bak.fexists)\n await fcopy(fp, fp_bak)\n \n await fwrite(fp, text)\n}\n\n"]}
|
|
1
|
+
{"version":3,"file":"file.js","sourceRoot":"","sources":["file.ts"],"names":[],"mappings":";;;;AAAA,2BAA2C;AAG3C,+DAAwB;AACxB,yEAA8B;AAC9B,uDAA+C;AAC/C,qEAA0B;AAC1B,iEAA2B;AAE3B,4EAAsC;AAGtC,+DAAuB;AAWd,cAXF,eAAG,CAWE;AAJZ,2CAAqC;AACrC,mCAAgC;AAChC,qDAAqB;AAOrB,SAAgB,UAAU;IACtB,OAAO,WAAG,GAAG,MAAM,CAAC,MAAM,CACtB,eAAG,CAAC,kBAAkB,CAClB,IAAI,eAAG,CAAC,MAAM,EAAE,CACnB,EACD,EAAE,IAAI,EAAE,eAAI,CAAC,IAAI,CAAC,IAAI,CAAC,eAAI,CAAC,EAAE,CACjC,CAAA;AACL,CAAC;AAPD,gCAOC;AAQM,KAAK,UAAU,KAAK,CAAE,EAAU,EAAE,EACrC,GAAG,EACH,QAAQ,GAAG,OAAO,EAClB,KAAK,GAAG,IAAI,KAIQ,EAAG;IAEvB,IAAI,GAAG;QACH,EAAE,GAAG,eAAI,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;SACtB,IAAI,CAAC,eAAI,CAAC,UAAU,CAAC,EAAE,CAAC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Q,GAAG,MAAM,MAIjB,EAAG;IACH,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAA;IAC1C,IAAI,MAAM,EAAE;QACR,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAA;QACjC,OAAM;KACT;IAED,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,kBAAkB,EAAE,UAAU,CAAC,EAAE,CAAA;IAC9E,IAAI,CAAC,MAAM,CAAC,OAAO;QACf,MAAM,KAAK,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;IAE3B,MAAM,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;AAC1B,CAAC;AAlBD,wBAkBC","sourcesContent":["import { promises as fsp, watch } from 'fs'\nimport type fs from 'fs'\n\nimport path from 'upath'\nimport iconv from 'iconv-lite'\nimport { readdirAsync } from 'readdir-enhanced'\nimport fse from 'fs-extra'\nimport rimraf from 'rimraf'\n\nimport debounce from 'lodash/debounce'\n\n\nimport MFS from 'memfs'\ndeclare module 'memfs' {\n interface IFs {\n join: typeof path.join\n }\n}\n\nimport { to_json } from './prototype'\nimport { dedent } from './utils'\nexport * from './ufs'\n\nexport { MFS }\n\nexport type Encoding = 'utf-8' | 'gb18030' | 'shift-jis' | 'binary'\n\n\nexport function create_mfs () {\n return mfs = Object.assign(\n MFS.createFsFromVolume(\n new MFS.Volume()\n ), \n { join: path.join.bind(path) }\n )\n}\n\nexport let mfs: MFS.IFs & { join: typeof path.join }\n\n\nexport async function fread (fp: string): Promise<string>\nexport async function fread (fp: string, { dir, encoding, print }?: { dir?: string, encoding: 'binary', print?: boolean }): Promise<Buffer>\nexport async function fread (fp: string, { dir, encoding, print }?: { dir?: string, encoding?: Encoding | 'auto', print?: boolean }): Promise<string>\nexport async function fread (fp: string, {\n dir, \n encoding = 'utf-8', \n print = true\n}: {\n dir?: string\n encoding?: Encoding | 'auto'\n print?: boolean } = { }\n) {\n if (dir)\n fp = path.join(dir, fp)\n else if (!path.isAbsolute(fp))\n throw new Error('fp must be absolute path, or pass in \"dir\" parameter')\n \n if (print)\n console.log(`read: ${fp}`)\n \n const buffer = await fsp.readFile(fp)\n \n if (encoding === 'binary')\n return buffer\n \n if (encoding === 'utf-8')\n return buffer.toString('utf8')\n \n if (encoding === 'auto') {\n const { detect } = await import('chardet')\n encoding = detect(buffer) as any\n if (print)\n console.log(`${fp} probably has encoding: ${encoding.toLowerCase()}`)\n }\n \n return iconv.decode(buffer, encoding)\n}\n\nexport async function fread_lines (fp: string, options: { dir?: string, encoding?: Exclude<Encoding, 'binary'> | 'auto', print?: boolean } = { }) {\n return (await fread(fp, options))\n .split_lines()\n}\n\nexport async function fread_json <T = any> (fp: string, options: { dir?: string, encoding?: Encoding, print?: boolean } = { }): Promise<T> {\n return JSON.parse(\n await fread(fp, options)\n )\n}\n\n\nexport async function fwrite (fp: string, data: Buffer, options?: { dir?: string, print?: boolean }): Promise<void>\nexport async function fwrite (fp: string, data: any, options?: { dir?: string, encoding?: Encoding, print?: boolean }): Promise<void>\nexport async function fwrite (fp: string, data: any, { dir, encoding = 'utf-8', print = true }: { dir?: string, encoding?: Encoding, print?: boolean } = { }) {\n if (dir)\n fp = path.join(dir, fp)\n else if (!path.isAbsolute(fp))\n throw new Error('fp must be absolute path, or pass in \"dir\" parameter')\n \n if (print)\n console.log('write:', fp)\n \n if (encoding === 'gb18030')\n data = iconv.encode(data, encoding)\n \n if (!Buffer.isBuffer(data) && typeof data !== 'string')\n data = to_json(data)\n \n await fsp.writeFile(fp, data)\n}\n\nexport async function fappend (fp: string, data: any, { dir, print = true }: { dir?: string, print?: boolean } = { }) {\n if (dir)\n fp = path.join(dir, fp)\n else if (!path.isAbsolute(fp))\n throw new Error('fp must be absolute path, or pass in \"dir\" parameter')\n \n if (print)\n console.log('append:', fp)\n \n if (!Buffer.isBuffer(data) && typeof data !== 'string')\n throw new Error('data is not Buffer or string')\n \n await fsp.appendFile(fp, data)\n}\n\n\n/**\n - fpd: absolute path of directory\n - optoins?:\n - deep?: `false` recursively\n - absolute?: `false` return absolute path\n - print?: `true`\n - filter?: `true` RegExp | (fp: string) => any\n*/\nexport async function flist (fpd: string, {\n filter, \n deep = false, \n absolute = false,\n print = true\n}: {\n filter?: RegExp | ((fp: string) => any)\n deep?: boolean\n absolute?: boolean\n print?: boolean\n} = { }) {\n if (!path.isAbsolute(fpd))\n throw new Error('fpd must be absolute path')\n \n let fps = await readdirAsync(fpd, {\n ...(absolute ? { basePath: fpd } : { }),\n deep,\n stats: false,\n })\n \n fps = fps.map( fp => {\n fp = path.normalize(fp)\n if (print)\n console.log(fp)\n return fp\n })\n \n if (filter instanceof RegExp)\n return fps.filter( fp => filter.test(fp))\n else if (filter)\n return fps.filter(filter)\n else\n return fps\n}\n\n\n/** delete file or directory (use rimraf to delete directory fast) \n - fp: path\n - options?:\n - print?: `true` (effective only delete single file)\n*/\nexport async function fdelete (fp: string, { print = true, fast = false }: { print?: boolean, fast?: boolean } = { }) {\n if (fp.length < 6) throw new Error(`${fp} too short`)\n if (!path.isAbsolute(fp))\n throw new Error('fpd must be absolute path')\n \n if (fp.is_dir) {\n if (print)\n console.log(`delete directory: ${fp}`.red)\n await new Promise<void>((resolve, reject) => {\n rimraf(fp, { glob: false, disableGlob: true }, error => {\n if (error)\n reject(error)\n else\n resolve()\n })\n })\n } else {\n if (print)\n console.log('delete:', fp)\n await fsp.unlink(fp)\n }\n}\n\n\n/** copy file or direcotry\n - src: src file/directory absolute path\n - dst: dst file/directory absolute path\n @example\n fcopy('d:/temp/camera/', 'd:/camera/')\n*/\nexport async function fcopy (src: string, dst: string, {\n print = true,\n overwrite = true,\n}: {\n print?: boolean\n overwrite?: boolean\n} = { }) {\n if (src.endsWith('/') !== dst.endsWith('/')) throw new Error('src and dst must be both file path or directory path')\n if (!path.isAbsolute(src) || !path.isAbsolute(dst)) throw new Error('src and dst must be absolute path')\n if (print)\n console.log(`copy: ${src} → ${dst}`)\n await fse.copy(src, dst, { overwrite, errorOnExist: true })\n}\n\n\n/** move file or direcotry\n - src: src file/directory absolute path\n - dst: dst file/directory absolute path\n @example\n fmove('d:/temp/camera/', 'd:/camera/')\n*/\nexport async function fmove (src: string, dst: string, {\n overwrite = false,\n print = true\n}: {\n overwrite?: boolean\n print?: boolean\n} = { }) {\n if (src.endsWith('/') !== dst.endsWith('/')) throw new Error('src and dst must be both file path or directory path')\n if (!path.isAbsolute(src) || !path.isAbsolute(dst)) throw new Error('src and dst must be absolute path')\n if (print)\n console.log(`move: ${src} → ${dst}`)\n await fse.move(src, dst, { overwrite })\n}\n\n\n/** rename file \n - fp: current filename/path\n - fp_: new filename/path\n - options?:\n - fpd?: fp and fp_ is in same directory\n - print?: `true`\n - overwrite?: `true` better performance without check\n */\nexport async function frename (\n fp: string, \n fp_: string,\n {\n fpd,\n print = true,\n overwrite = true\n }: {\n fpd?: string\n print?: boolean\n overwrite?: boolean\n } = { }\n) {\n if (fpd) {\n fp = path.join(fpd, fp)\n fp_ = path.join(fpd, fp_)\n } else if (!path.isAbsolute(fp) || !path.isAbsolute(fp_))\n throw new Error('fp and fp_ must be absolute path')\n \n if (print)\n console.log('rename:', fp, '→', fp_)\n \n if (!overwrite && fp_.fexists)\n throw new Error(`file already exists:${fp_}`)\n \n await fsp.rename(fp, fp_)\n}\n\n\nexport async function fmkdir (fpd: string, options: fs.MakeDirectoryOptions & { print?: boolean, suppress_existence?: boolean } = { }) {\n if (!path.isAbsolute(fpd))\n throw new Error('fpd must be absolute path')\n \n options.print ??= true\n \n if (fpd.fexists)\n if (fpd.is_dir) {\n if (options.print && !options.suppress_existence)\n console.log('directory already exists:', fpd)\n return\n } else throw new Error(`file with same name already exists, cannot create directory: ${fpd}`)\n else if (options.print)\n console.log('create new directory:', fpd)\n \n await fsp.mkdir(fpd, { recursive: true })\n}\n\n\n/** - link: can be file path or directory path */\nexport async function flink (\n fp_real: string, \n fp_link: string, \n {\n junction = false,\n print = true \n }: { \n junction?: boolean\n print?: boolean\n} = { }) {\n if (!path.isAbsolute(fp_real) || !path.isAbsolute(fp_link))\n throw new Error('fpd must be absolute path')\n \n if (fp_link.fexists)\n if (fp_link.is_dir)\n fp_link = path.join(fp_link, fp_real.fname)\n else if ( (await fsp.lstat(fp_link)).isSymbolicLink() ) {\n console.log('link already exists:', fp_link)\n return\n } else\n throw new Error('file with same name already exists, cannot create new link')\n \n \n if (print)\n console.log(`source file ${fp_real} linked to ${fp_link}`)\n \n if (junction)\n fsp.symlink(fp_real, fp_link, 'junction')\n else\n fsp.symlink(fp_real, fp_link, fp_real.is_dir ? 'dir' : 'file')\n}\n\n\nexport function link_shortcut (target: string, name: string, { args }: { args?: string[] } = { }) {\n const cmd = dedent`\n $wsh_shell = New-Object -comObject WScript.Shell\n $shortcut = $wsh_shell.CreateShortcut(\"d:/links/#{name}.lnk\")\n $shortcut.TargetPath = '${target}'\n $shortcut.Arguments = \"${args || ''}\"\n $shortcut.WorkingDirectory = '${target.fdir}'\n ${ target.is_dir ? '$shortcut.IconLocation = \"%SystemRoot%\\\\System32\\\\SHELL32.dll,3\"' : '' }\n $shortcut.Save()\n `\n console.log(cmd)\n // await psh(cmd)\n}\n\n\nexport let fwatchers: Record<string, fs.FSWatcher> = { }\n\n/**\n - fp: path of file or directory\n - callback: called when modified\n - exec: call callback when watch is executed\n save fs.FSWatcher in watchers, subsequent call will auto close existing watcher for the same fp\n \n https://nodejs.org/dist/latest-v15.x/docs/api/fs.html#fs_fs_watch_filename_options_listener \n The listener callback gets two arguments (event, filename). \n event is either 'rename' or 'change', and filename is the name of the file which triggered the event.\n On most platforms, 'rename' is emitted whenever a filename appears or disappears in the directory.\n \n The listener callback is attached to the 'change' event fired by fs.FSWatcher, but it is not the same thing as the 'change' value of event. \n \n*/\nexport async function fwatch (\n fp: string, \n onchange: (event: string, filename: string) => any,\n { exec = true }: { exec?: boolean } = { }\n) {\n if (!path.isAbsolute(fp)) throw new Error('fp must be absolute path')\n \n const _watcher = fwatchers[fp]\n if (_watcher)\n _watcher.close()\n \n if (exec)\n await onchange('change', fp)\n \n const debounced_onchange = debounce((event, filename) => {\n console.log(`file changed (${event}): ${filename}`)\n onchange(event, path.normalize(filename))\n }, 500, { leading: false, trailing: true })\n const watcher = watch(fp, debounced_onchange)\n watcher.on('error', error => { console.error(error) })\n return fwatchers[fp] = watcher\n}\n\n\n/** open a file and replace certain pattern */\nexport async function freplace (fp: string, pattern: string | RegExp, replacement: string) {\n await fwrite(\n fp,\n (await fread(fp))\n .replaceAll(pattern, replacement)\n )\n}\n\n/** convert file encoding to UTF-8\n - fp: file absolute path\n - options?:\n - dryrun?: `true`\n - encoding?: `'auto'`\n*/\nexport async function f2utf8 (fp: string, {\n dryrun = true,\n encoding = 'auto',\n}: {\n dryrun?: boolean\n encoding?: Encoding | 'auto'\n} = { }) {\n const text = await fread(fp, { encoding })\n if (dryrun) {\n console.log(text.slice(0, 10000))\n return\n }\n \n const fp_bak = `${fp.fdir}${fp.fname.replace(/(.*?)(\\.[^.]+)?$/, '$1.bak$2')}`\n if (!fp_bak.fexists)\n await fcopy(fp, fp_bak)\n \n await fwrite(fp, text)\n}\n\n"]}
|
package/i18n/README.md
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
# xshell/i18n
|
|
2
|
+
|
|
3
|
+
## TL;DR
|
|
4
|
+
npm i xshell/i18n
|
|
5
|
+
```typescript
|
|
6
|
+
import I18N from 'xshell/i18n'
|
|
7
|
+
|
|
8
|
+
const i18n = new I18N({
|
|
9
|
+
'你好,世界!': {
|
|
10
|
+
en: 'Hello, world!',
|
|
11
|
+
ja: 'こんにちは世界!',
|
|
12
|
+
ko: '안녕하세요!'
|
|
13
|
+
}
|
|
14
|
+
}, /* 浏览器中可不传,会自动判断 */ 'ja')
|
|
15
|
+
|
|
16
|
+
console.log(i18n.t('你好,世界!'))
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## 功能
|
|
20
|
+
- 动态翻译字段: `i18n.r(field)`
|
|
21
|
+
|
|
22
|
+
- 静态翻译文本: `i18n.t('文本')`
|
|
23
|
+
|
|
24
|
+
- 作为 NodeJS 中间件处理请求 (Koa, Express, Egg.js, ...),解析语言,提供 request scope 的翻译函数
|
|
25
|
+
|
|
26
|
+
- React Trans 组件:
|
|
27
|
+
```html
|
|
28
|
+
<Trans count={count} tOptions={{ context: 'asdf' }}>
|
|
29
|
+
Hello <strong title="this is your name">{{name}}</strong>, you have {{count}} unread message(s). <a href="/msgs">Go to messages</a>.
|
|
30
|
+
</Trans>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
- 扫描代码中的词条: `i18n-scan -i "src/**/*.{ts,tsx,js,jsx,ejs}"`
|
|
34
|
+
|
|
35
|
+
- 自动标记中文词条
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## 特性
|
|
39
|
+
- 基于 i18next, react-i18next 封装,支持单复数,context, 变量插值 等
|
|
40
|
+
|
|
41
|
+
- 按照一定的优先级自动解析用户首选语言和国内/国际来源,可同时在浏览器环境和 NodeJS 中使用
|
|
42
|
+
|
|
43
|
+
- 翻译语言缺失自动 fallback: ja/ko -> en -> zh -> key
|
|
44
|
+
|
|
45
|
+
- 可手工编辑的词典文件格式
|
|
46
|
+
|
|
47
|
+
## API
|
|
48
|
+
```typescript
|
|
49
|
+
class I18N {
|
|
50
|
+
/** (ISO 639-1 标准语言代码) 可能取 zh, en, ja, ko */
|
|
51
|
+
language: 'zh' | 'en' | 'ja' | 'ko'
|
|
52
|
+
|
|
53
|
+
/** 标记静态文本,以便扫描词条,并在运行时根据当前语言获取翻译 */
|
|
54
|
+
t : (text: string, options?: { language?: Language, context?: string, count?: number, [key: string]: any }) => string
|
|
55
|
+
|
|
56
|
+
/** render: 翻译配置字段 */
|
|
57
|
+
r : (field: Item | undefined | null) => string
|
|
58
|
+
|
|
59
|
+
/** hostname shortcuts */
|
|
60
|
+
hosts: Hosts
|
|
61
|
+
|
|
62
|
+
/** url prefix shortcuts */
|
|
63
|
+
roots: Roots
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** 配置字段 */
|
|
67
|
+
interface Item {
|
|
68
|
+
zh?: string
|
|
69
|
+
en?: string
|
|
70
|
+
ja?: string
|
|
71
|
+
ko?: string
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## 使用方法
|
|
76
|
+
### 一、NodeJS 中使用
|
|
77
|
+
```typescript
|
|
78
|
+
const _dict = require('<project>/i18n/dict.json') // 项目词典文件
|
|
79
|
+
|
|
80
|
+
new I18N(_dict, 'en')
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
### 二、浏览器中使用
|
|
85
|
+
```typescript
|
|
86
|
+
import { I18N, Trans } from 'xshell/i18n'
|
|
87
|
+
import _dict from '<project>/i18n/dict.json' // 项目词典文件
|
|
88
|
+
|
|
89
|
+
export let i18n = new I18N(_dict /* , language 浏览器中可不传 language 参数,会自动判断 */)
|
|
90
|
+
|
|
91
|
+
const { t, r, Trans, intl } = i18n
|
|
92
|
+
|
|
93
|
+
// 可用于判断是否为国际站
|
|
94
|
+
i18n.intl === true
|
|
95
|
+
|
|
96
|
+
i18n.t('文本') === t('文本') === '文本翻译'
|
|
97
|
+
|
|
98
|
+
i18n.language = 'en' // 所有方法已绑定在 i18n 上,修改语言后函数会使用新设置的语言
|
|
99
|
+
t('文本') === '根据新的 i18n.language 翻译'
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
// 高级用法
|
|
103
|
+
// 单复数
|
|
104
|
+
t('共有 {{count}} 个人', { context: 'button', count: 3 })
|
|
105
|
+
|
|
106
|
+
// 变量插值
|
|
107
|
+
t('{{minutes}}分 {{seconds}}秒 内完成支付', { minutes: 3, seconds: 40 })
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
// 翻译特定格式的配置字段
|
|
111
|
+
if (obj === { zh: '中文', en: 'english', ja: '日本語', ko: '...' })
|
|
112
|
+
i18n.r(obj) === '根据 i18n.language 输出翻译结果'
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
#### Trans 组件
|
|
117
|
+
```jsx
|
|
118
|
+
import { I18N, Trans } from 'xshell/i18n'
|
|
119
|
+
|
|
120
|
+
// import _dict from '<project>/i18n/dict.json'
|
|
121
|
+
const _dict = {
|
|
122
|
+
"阅读更多": {
|
|
123
|
+
"en": "Read more",
|
|
124
|
+
"ja": "もっとご覧になる",
|
|
125
|
+
"ko": "더 읽어보기"
|
|
126
|
+
},
|
|
127
|
+
"',\",<,>为非法字符,请重新输入!": {
|
|
128
|
+
"en": ", \", <, and > are invalid characters. Please enter again.",
|
|
129
|
+
},
|
|
130
|
+
"书": {
|
|
131
|
+
"ja": "{{count}}冊の本",
|
|
132
|
+
"en": "{{count}} book",
|
|
133
|
+
},
|
|
134
|
+
"书_plural": {
|
|
135
|
+
"en": "{{count}} books",
|
|
136
|
+
},
|
|
137
|
+
"test_key": {
|
|
138
|
+
"en": "Hello <1>{{name}}</1>, you have {{count}} unread message. <5>Go to message</5>.",
|
|
139
|
+
"zh": "你好 <1>{{name}}</1>, you have {{count}} unread message. <5>Go to message</5>.",
|
|
140
|
+
},
|
|
141
|
+
"test_key_plural": {
|
|
142
|
+
"en": "Hello <1>{{name}}</1>, you have {{count}} unread messages. <5>Go to messages</5>.",
|
|
143
|
+
},
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// init <Trans> by side effects
|
|
147
|
+
let i18n = new I18N(_dict)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
function TestTrans () {
|
|
151
|
+
const count = 3
|
|
152
|
+
const name = 'hongfeishen'
|
|
153
|
+
|
|
154
|
+
return (<div>
|
|
155
|
+
<Trans count={count} tOptions={{ lng: 'zh' }}>Hello <strong title="this is your name">{{name}}</strong>, you have {{count}} unread message(s). <a href="/msgs">Go to messages</a>.</Trans><br/>
|
|
156
|
+
<Trans>联系我们</Trans><br/>
|
|
157
|
+
<Trans tOptions={{ language: 'ko' }}>阅读更多</Trans><br/>
|
|
158
|
+
<Trans tOptions={{ context: 'pricecenter' }}>阅读更多</Trans><br/>
|
|
159
|
+
<Trans tOptions={{ context: 'pricecenter', lng: 'ja' }}>阅读更多</Trans><br/>
|
|
160
|
+
<Trans count={0}>书</Trans><br/>
|
|
161
|
+
<Trans count={1}>书</Trans><br/>
|
|
162
|
+
<Trans count={2}>书</Trans><br/>
|
|
163
|
+
</div>)
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
更多 Trans 组件用法请参考 [react-i18next 文档](https://react.i18next.com/guides/quick-start)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
## 词条扫描以及更新翻译的方法
|
|
171
|
+
### 整体流程
|
|
172
|
+

|
|
173
|
+
|
|
174
|
+
### 词条标记
|
|
175
|
+
#### 词条标记文档
|
|
176
|
+
https://react.i18next.com/guides/quick-start
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
#### 使用 ESLint 的 fix 功能自动标记代码中的中文词条
|
|
180
|
+
```shell
|
|
181
|
+
npm i eslint eslint-plugin-i18n --save-dev
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
安装完后在项目的 `.eslintrc.json` 中加入以下配置启用 i18n 规则 (完整配置可参考本项目中的 .eslintrc.json)
|
|
185
|
+
```json
|
|
186
|
+
{
|
|
187
|
+
"parser": "@typescript-eslint/parser",
|
|
188
|
+
"plugins": [
|
|
189
|
+
...
|
|
190
|
+
"i18n"
|
|
191
|
+
],
|
|
192
|
+
"rules": {
|
|
193
|
+
...
|
|
194
|
+
"i18n/no-chinese-character": "error",
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### 词条扫描
|
|
200
|
+
可扫描代码中的 `t` 静态标记以及 `Trans 组件`,支持 .js, .jsx, .ts, .tsx, .ejs 文件
|
|
201
|
+
|
|
202
|
+
请升级 NodeJS 到最新版本,并确保含有 `Trans 组件` 所在的文件后缀为 `.jsx` 或 `.tsx`,否则 `Trans 组件` 不会被扫描到
|
|
203
|
+
|
|
204
|
+
### 扫描流程
|
|
205
|
+
1. 在项目中安装 xshell 后,会生成 i18n-scan 命令
|
|
206
|
+
|
|
207
|
+
2. 在项目 package.json 的 scripts 中加入脚本:`"scan": "i18n-scan --input \"src/**/*.{ts,tsx,js,jsx,ejs}\" --output i18n/",`
|
|
208
|
+
|
|
209
|
+
3. 使用 `npm run scan` 扫描词条,会创建或修改 `./i18n/` 下的:
|
|
210
|
+
① `scanneds.json` 代码中扫描到的词条及其翻译 (仅本次 --input 所包含代码中的词条及翻译)
|
|
211
|
+
② `source/zh.json`, `source/en.json`, ... (`scanneds.json` 对应的 tea 词条格式,可提交到翻译仓库交由翻译团队翻译)
|
|
212
|
+
③ `dict.json` 完整的词典文件 (历史所有词条词条及翻译,会被打包到代码中在运行时决定词条翻译)
|
|
213
|
+
|
|
214
|
+
4. 补齐 `scanneds.json` 中的翻译,可以选择下面两种方法之一补充翻译:
|
|
215
|
+
- 【方法一】交由翻译团队翻译:将 `source/zh.json` 等文件提交到翻译仓库 https://git.woa.com/intl-platform/intl-console-translation ,并创建 TAPD 单,待 `en.json`, 等翻译返回后放到 `source/` 中覆盖原来的文件
|
|
216
|
+
- 自动化提交翻译词条配置可以参考文档 http://tapd.oa.com/tcp_access/markdown_wikis/show/#1220399462000786583
|
|
217
|
+
- 配置完成后先运行 `npm run dict-pull` 拉取仓库中的词条翻译到本地
|
|
218
|
+
- 再运行 `npm run scan` 生成待翻译词条
|
|
219
|
+
- 最后运行 `npm run dict-push -- --lang en` 上传待翻译词条到仓库,提交 TAPD 单等待翻译团队翻译词条
|
|
220
|
+
- 翻译团队完成翻译后再将词条拉取到本地 `npm run dict-pull`
|
|
221
|
+
- 【方法二】手动补充词条翻译:手动补全扫描结果 `scanneds.json` 中未翻译的词条
|
|
222
|
+
|
|
223
|
+
5. 通过以上 `"4."` 步骤补充翻译后重新运行扫描 `npm run scan`,这次扫描会自动根据 `source/en.json` 以及 `scanneds.json` 更新 `dict.json`。最终构建时 `dict.json` 内的词条会被打包进 js, 通过 i18n.init(<dict.json>) 加载
|
|
224
|
+
|
|
225
|
+

|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
### 词典文件 dict.json 格式
|
|
229
|
+
新增词条可在文件尾部加入,已有词条可直接补充翻译
|
|
230
|
+
```ts
|
|
231
|
+
{
|
|
232
|
+
// 词条 key
|
|
233
|
+
"已有词条": {
|
|
234
|
+
"zh": "xxxxx", // 一般不需要设置中文翻译,默认为词条 key 使用中文
|
|
235
|
+
// 在此加入 "en" 和 "ja" 等翻译,暂时没有对应语言的词条可跳过,无需设置空字符串
|
|
236
|
+
},
|
|
237
|
+
|
|
238
|
+
...
|
|
239
|
+
|
|
240
|
+
"阅读更多": {
|
|
241
|
+
"en": "Read more",
|
|
242
|
+
"ja": "もっとご覧になる",
|
|
243
|
+
"ko": "더 읽어보기"
|
|
244
|
+
},
|
|
245
|
+
|
|
246
|
+
...
|
|
247
|
+
|
|
248
|
+
// _plural 后缀表示单复数形式, 用来区分相同短语的单复数形式,并通过 i18n.t('书', { count: 3 }) 调用自动选择正确的单复数形式
|
|
249
|
+
"书": {
|
|
250
|
+
"ja": "{{count}}冊の本",
|
|
251
|
+
"en": "{{count}} book",
|
|
252
|
+
},
|
|
253
|
+
"书_plural": {
|
|
254
|
+
"en": "{{count}} books",
|
|
255
|
+
},
|
|
256
|
+
|
|
257
|
+
...
|
|
258
|
+
|
|
259
|
+
// _button 后缀表示 context, 用来区分相同中文短语的不同使用场合的词条,并通过 i18n.t('提交', { context: 'button' }) 调用选择正确的翻译
|
|
260
|
+
"提交_button": {
|
|
261
|
+
"ja": "",
|
|
262
|
+
"en": "{{count}} book",
|
|
263
|
+
},
|
|
264
|
+
"提交": {
|
|
265
|
+
"ja": "{{count}}冊の本",
|
|
266
|
+
"en": "{{count}} book",
|
|
267
|
+
},
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
## Runtime Dependencies
|
|
273
|
+
- i18next
|
|
274
|
+
- js-cookie
|
|
275
|
+
- qs
|
|
276
|
+
- 使用 Trans 组件时
|
|
277
|
+
- react
|
|
278
|
+
- react-i18next
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
## 作者
|
|
282
|
+
ShenHongFei (沈鸿飞)
|
|
283
|
+
|
package/i18n/dict.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Language } from './index';
|
|
2
|
+
export declare class Dict {
|
|
3
|
+
_dict: _Dict;
|
|
4
|
+
constructor(_dict?: _Dict);
|
|
5
|
+
get(key: string): Item | undefined;
|
|
6
|
+
get(key: string, language: Language): string | '';
|
|
7
|
+
to_resources(): {
|
|
8
|
+
zh: {
|
|
9
|
+
translation: {};
|
|
10
|
+
};
|
|
11
|
+
en: {
|
|
12
|
+
translation: {};
|
|
13
|
+
};
|
|
14
|
+
ja: {
|
|
15
|
+
translation: {};
|
|
16
|
+
};
|
|
17
|
+
ko: {
|
|
18
|
+
translation: {};
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** 配置字段 */
|
|
23
|
+
export declare type Item = {
|
|
24
|
+
[language in Language]?: string;
|
|
25
|
+
};
|
|
26
|
+
/** JSON.parse(词典文件.json) 得到的对象 */
|
|
27
|
+
export interface _Dict {
|
|
28
|
+
[key: string]: Item;
|
|
29
|
+
}
|
|
30
|
+
export default Dict;
|
package/i18n/dict.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Dict = void 0;
|
|
4
|
+
class Dict {
|
|
5
|
+
constructor(_dict = {}) {
|
|
6
|
+
this._dict = _dict;
|
|
7
|
+
}
|
|
8
|
+
get(key, language) {
|
|
9
|
+
if (!key)
|
|
10
|
+
return '';
|
|
11
|
+
const item = this._dict[key];
|
|
12
|
+
if (!item || !language)
|
|
13
|
+
return item || '';
|
|
14
|
+
return item[language] || '';
|
|
15
|
+
}
|
|
16
|
+
to_resources() {
|
|
17
|
+
return Object.entries(this._dict).reduce((acc, [key, item]) => {
|
|
18
|
+
Object.entries(item).forEach(([language, translation]) => {
|
|
19
|
+
if (!translation || !acc[language])
|
|
20
|
+
return;
|
|
21
|
+
acc[language].translation[key] = translation;
|
|
22
|
+
});
|
|
23
|
+
return acc;
|
|
24
|
+
}, {
|
|
25
|
+
zh: { translation: {} },
|
|
26
|
+
en: { translation: {} },
|
|
27
|
+
ja: { translation: {} },
|
|
28
|
+
ko: { translation: {} },
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.Dict = Dict;
|
|
33
|
+
exports.default = Dict;
|
|
34
|
+
//# sourceMappingURL=dict.js.map
|
package/i18n/dict.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dict.js","sourceRoot":"","sources":["dict.ts"],"names":[],"mappings":";;;AAEA,MAAa,IAAI;IAGb,YAAa,QAAe,EAAE;QAC1B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACtB,CAAC;IAID,GAAG,CAAE,GAAW,EAAE,QAAmB;QACjC,IAAI,CAAC,GAAG;YAAE,OAAO,EAAE,CAAA;QACnB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAC5B,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ;YAAE,OAAO,IAAI,IAAI,EAAE,CAAA;QACzC,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAA;IAC/B,CAAC;IAED,YAAY;QACR,OAAO,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAE,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE;YAC3D,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,CAAE,CAAC,CAAE,QAAQ,EAAE,WAAW,CAAE,EAAE,EAAE;gBACxD,IAAI,CAAC,WAAW,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC;oBAAE,OAAM;gBAC1C,GAAG,CAAC,QAAQ,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,WAAW,CAAA;YAChD,CAAC,CAAC,CAAA;YACF,OAAO,GAAG,CAAA;QACd,CAAC,EAAE;YACC,EAAE,EAAE,EAAE,WAAW,EAAE,EAAG,EAAE;YACxB,EAAE,EAAE,EAAE,WAAW,EAAE,EAAG,EAAE;YACxB,EAAE,EAAE,EAAE,WAAW,EAAE,EAAG,EAAE;YACxB,EAAE,EAAE,EAAE,WAAW,EAAE,EAAG,EAAE;SAC3B,CAAC,CAAA;IACN,CAAC;CACJ;AA9BD,oBA8BC;AAeD,kBAAe,IAAI,CAAA","sourcesContent":["import { Language } from './index'\n\nexport class Dict {\n _dict: _Dict\n \n constructor (_dict: _Dict = {}) {\n this._dict = _dict\n }\n \n get (key: string): Item | undefined\n get (key: string, language: Language): string | ''\n get (key: string, language?: Language) {\n if (!key) return ''\n const item = this._dict[key]\n if (!item || !language) return item || ''\n return item[language] || ''\n }\n \n to_resources () {\n return Object.entries(this._dict).reduce( (acc, [key, item]) => {\n Object.entries(item).forEach( ([ language, translation ]) => {\n if (!translation || !acc[language]) return\n acc[language].translation[key] = translation\n })\n return acc\n }, {\n zh: { translation: { } },\n en: { translation: { } },\n ja: { translation: { } },\n ko: { translation: { } },\n })\n }\n}\n\n\n/** 配置字段 */\nexport type Item = {\n [language in Language]?: string\n}\n\n\n/** JSON.parse(词典文件.json) 得到的对象 */\nexport interface _Dict {\n [key: string]: Item\n}\n\n\nexport default Dict\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const upath_1 = (0, tslib_1.__importDefault)(require("upath"));
|
|
6
|
+
const commander_1 = require("commander");
|
|
7
|
+
const scanner_1 = (0, tslib_1.__importDefault)(require("./scanner"));
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
commander_1.program.name('i18n-scan')
|
|
10
|
+
.option('-r, --rootdir [rootdir]', '根目录:默认为当前工作目录', upath_1.default.normalize(process.cwd()))
|
|
11
|
+
.option('-i, --input [input]', '扫描 pattern:多个 pattern 用分号分割,采用 glob pattern 匹配,如 `src/**/*.{js,jsx,ts,tsx}`', v => v.split(';'))
|
|
12
|
+
.option('-o, --output [output]', 'i18n 目录:默认为 <rootdir>/i18n/')
|
|
13
|
+
.option('-c, --config [config]', '自定义配置文件,默认为 <rootdir>/i18n/config.js ,可参考默认配置 xshell/i18n/index.ts 以及 https://github.com/i18next/i18next-scanner', 'i18n/config.js')
|
|
14
|
+
.parse(process.argv);
|
|
15
|
+
const { rootdir, config, input, output } = commander_1.program.opts();
|
|
16
|
+
(0, scanner_1.default)(rootdir, {
|
|
17
|
+
...(0, utils_1.try_require)(upath_1.default.resolve(rootdir, config)),
|
|
18
|
+
...input ? { input } : {},
|
|
19
|
+
...output ? { output } : {},
|
|
20
|
+
});
|
|
21
|
+
//# sourceMappingURL=i18n-scan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n-scan.js","sourceRoot":"","sources":["i18n-scan.ts"],"names":[],"mappings":";;;;AAEA,+DAAwB;AACxB,yCAAmC;AAEnC,qEAA+B;AAC/B,mCAAqC;AAErC,mBAAO,CAAC,IAAI,CAAC,WAAW,CAAC;KACpB,MAAM,CAAC,yBAAyB,EAAK,eAAe,EAAE,eAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;KACpF,MAAM,CAAC,qBAAqB,EAAS,6EAA6E,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;KACtI,MAAM,CAAC,uBAAuB,EAAO,6BAA6B,CAAC;KACnE,MAAM,CAAC,uBAAuB,EAAO,kHAAkH,EAAE,gBAAgB,CAAC;KAC1K,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;AAExB,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,mBAAO,CAAC,IAAI,EAAE,CAAA;AACzD,IAAA,iBAAO,EAAC,OAAO,EAAE;IACb,GAAI,IAAA,mBAAW,EAAE,eAAI,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAE;IAChD,GAAI,KAAK,CAAE,CAAC,CAAE,EAAE,KAAK,EAAE,CAAG,CAAC,CAAE,EAAG;IAChC,GAAI,MAAM,CAAC,CAAC,CAAE,EAAE,MAAM,EAAE,CAAE,CAAC,CAAE,EAAG;CACnC,CAAC,CAAA","sourcesContent":["#!/usr/bin/env node\n\nimport path from 'upath'\nimport { program } from 'commander'\n\nimport scanner from './scanner'\nimport { try_require } from './utils'\n\nprogram.name('i18n-scan')\n .option('-r, --rootdir [rootdir]' , '根目录:默认为当前工作目录', path.normalize(process.cwd()))\n .option('-i, --input [input]' , '扫描 pattern:多个 pattern 用分号分割,采用 glob pattern 匹配,如 `src/**/*.{js,jsx,ts,tsx}`', v => v.split(';'))\n .option('-o, --output [output]' , 'i18n 目录:默认为 <rootdir>/i18n/')\n .option('-c, --config [config]' , '自定义配置文件,默认为 <rootdir>/i18n/config.js ,可参考默认配置 xshell/i18n/index.ts 以及 https://github.com/i18next/i18next-scanner', 'i18n/config.js')\n .parse(process.argv)\n\nconst { rootdir, config, input, output } = program.opts()\nscanner(rootdir, {\n ... try_require( path.resolve(rootdir, config) ),\n ... input ? { input } : { },\n ... output ? { output } : { },\n})\n"]}
|
package/i18n/i18n.ico
ADDED
|
Binary file
|
package/i18n/index.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { i18n as I18Next } from 'i18next';
|
|
2
|
+
import type { Trans } from 'react-i18next';
|
|
3
|
+
import type { _Dict, Item } from './dict';
|
|
4
|
+
export declare type Language = 'zh' | 'en' | 'ja' | 'ko';
|
|
5
|
+
export declare const LANGUAGES: readonly ["zh", "en", "ja", "ko"];
|
|
6
|
+
declare global {
|
|
7
|
+
interface Window {
|
|
8
|
+
language: Language;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
提供翻译文本功能,在浏览器环境下自动解析当前语言、国际/国内用户
|
|
13
|
+
@see https://github.com/ShenHongFei/xshell/i18n/
|
|
14
|
+
*/
|
|
15
|
+
export declare class I18N {
|
|
16
|
+
static LANGUAGE_REGEXP: RegExp;
|
|
17
|
+
/** (ISO 639-1 标准语言代码) 可能取 zh, en, ja, ko */
|
|
18
|
+
language: Language;
|
|
19
|
+
/** hostname shortcuts */
|
|
20
|
+
hosts: Hosts;
|
|
21
|
+
/** url prefix shortcuts */
|
|
22
|
+
roots: Roots;
|
|
23
|
+
/** 标记静态文本,以便扫描词条,并在运行时根据当前语言获取翻译 */
|
|
24
|
+
t: (text: string, options?: {
|
|
25
|
+
language?: Language;
|
|
26
|
+
context?: string;
|
|
27
|
+
count?: number;
|
|
28
|
+
[key: string]: any;
|
|
29
|
+
}) => string;
|
|
30
|
+
/** render: 翻译配置字段 */
|
|
31
|
+
r: (field: Item | undefined | null) => string;
|
|
32
|
+
i18next: I18Next;
|
|
33
|
+
/** react-i18next <Trans/> 组件 */
|
|
34
|
+
Trans: typeof Trans;
|
|
35
|
+
/** ```ts
|
|
36
|
+
import dict from './dict.json' // { "添加": { "en": "Add", "ja": "追加", "ko": "추가" } }
|
|
37
|
+
|
|
38
|
+
const i18n = new I18N(dict, 'zh') // 创建实例,传入词典 dict 并指定语言(NodeJS 环境),
|
|
39
|
+
const i18n = new I18N(dict) // 创建实例,传入词典 dict 并自动判断当前语言(浏览器环境),
|
|
40
|
+
const i18n = new I18N({ }) // 创建实例,传入空词典
|
|
41
|
+
```
|
|
42
|
+
@see https://github.com/ShenHongFei/xshell/i18n/
|
|
43
|
+
*/
|
|
44
|
+
constructor(_dict: _Dict, language?: Language);
|
|
45
|
+
/** 加载词典文件 (需要将这两行单独放一个文件里,以保证在 import 其他文件之前执行)
|
|
46
|
+
|
|
47
|
+
@example
|
|
48
|
+
import dict from './dict.json' // { "添加": { "en": "Add", "ja": "追加", "ko": "추가" } }
|
|
49
|
+
i18n.init(dict)
|
|
50
|
+
*/
|
|
51
|
+
init(dict: _Dict): void;
|
|
52
|
+
toJSON(): {
|
|
53
|
+
language: Language;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export interface Hosts {
|
|
57
|
+
}
|
|
58
|
+
export interface Roots {
|
|
59
|
+
}
|
|
60
|
+
export type { _Dict, Item };
|
|
61
|
+
export interface I18NBasic {
|
|
62
|
+
intl: boolean;
|
|
63
|
+
language: Language;
|
|
64
|
+
}
|
|
65
|
+
export default I18N;
|