-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
284 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,39 @@ | ||
# ts_deno_cn2tw | ||
<en_us>Translate files from Simplified Chinese to Traditional Chinese.</en_us> <zh_cn>翻译文件中的简体中文到繁体中文。</zh_cn> <zh_tw>翻譯文件中的簡體中文到繁體中文。</zh_tw> | ||
javascript: https://github.com/anqisoft/js_node_cn2tw<br> | ||
npmjs: https://www.npmjs.com/package/@dishanqian/cn2tw | ||
|
||
### import | ||
``` typescript | ||
import { convert } from 'https://deno.land/x/[email protected]/index.ts'; | ||
``` | ||
|
||
### Usage1 | ||
``` typescript | ||
deno run --allow-run --allow-read --allow-write https://deno.land/x/[email protected]/index.ts ~sourceFilename~ ~goalFilename~ | ||
``` | ||
|
||
### Usage2 | ||
``` typescript | ||
import { convert } from 'https://deno.land/x/[email protected]/index.ts'; | ||
convert(~sourceFilename1~ ~goalFilename1~); | ||
convert(~sourceFilename2~ ~goalFilename2~); | ||
``` | ||
|
||
## <en_us> | ||
Translate file content from Simplified Chinese to Traditional Chinese.<br> | ||
Created on Wed Jan 10 2024 16:56:00<br> | ||
Feature: Translate file content from Simplified Chinese to Traditional Chinese. | ||
</en_us><br> | ||
|
||
## <zh_cn> | ||
翻译文件中的简体中文到繁体中文。<br> | ||
创建:2024年1月10日 16:56:00<br> | ||
功能:翻译文件中的简体中文到繁体中文。 | ||
</zh_cn><br> | ||
|
||
## <zh_tw> | ||
|
||
翻譯文件中的簡體中文到繁體中文。<br> | ||
創建:2024年1月10日 16:56:00<br> | ||
功能:翻譯文件中的簡體中文到繁體中文。 | ||
</zh_tw> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
cd.. | ||
tsc --declaration -p .\ -t es2020 --emitDeclarationOnly --outDir . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@echo off | ||
@del /s/q "%CD%\..\dist\*.min.js" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
@echo off | ||
|
||
:: npm install uglify-js -g | ||
:: git clone git://github.com/mishoo/UglifyJS2.git | ||
:: uglifyjs --help | ||
:: * -o, ¨Coutput [string] | ||
:: * -b, ¨Cbeautify [string] | ||
:: * -m, ¨Cmangle [string] | ||
:: uglifyjs lazyLoad.js -m -o lazyLoad.min.js | ||
|
||
set JS_FOLDER="%CD%\..\dist\" | ||
chdir /d %JS_FOLDER% | ||
|
||
setlocal enabledelayedexpansion | ||
|
||
title "Compressing the js files of %JS_FOLDER%" | ||
|
||
for /r . %%a in (*.js) do ( | ||
set src=%%~fa | ||
|
||
REM Use "!src:~-7!", not !src:~-7! | ||
if "!src:~-7!" neq ".min.js" ( | ||
echo !src! | ||
set goal=!src:.js=.min.js! | ||
start /B "" uglifyjs !src! -m -o !goal! | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@ECHO OFF | ||
set deno_json_path=%cd%\..\..\deno.json | ||
cd ..\..\ | ||
|
||
deno bundle -c %deno_json_path% --no-check index.ts dist\index.js || pause | ||
|
||
cd bat\ | ||
call compressJs.bat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@ECHO OFF | ||
deno fmt | ||
|
||
pause |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@ECHO OFF | ||
deno lint | ||
|
||
pause |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"compilerOptions": { | ||
"allowJs": true, | ||
"lib": ["deno.window", "dom", "es2020"], | ||
"strict": true | ||
}, | ||
"importMap": "import_map.json", | ||
"lint": { | ||
"include": ["./*.ts"], | ||
"exclude": ["./*.d.ts"], | ||
"rules": { | ||
"tags": ["recommended"], | ||
"include": ["ban-untagged-todo"], | ||
"exclude": ["no-unused-vars"] | ||
} | ||
}, | ||
"fmt": { | ||
"include": ["./*.ts"], | ||
"exclude": ["./*.d.ts"], | ||
"useTabs": true, | ||
"lineWidth": 100, | ||
"indentWidth": 2, | ||
"singleQuote": true, | ||
"proseWrap": "preserve" | ||
}, | ||
"test": { | ||
"include": [], | ||
"exclude": [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
"use strict"; | ||
/* | ||
* Copyright (c) 2024 [email protected] | ||
* index.ts | ||
* | ||
* Usage: ``` | ||
deno run --allow-run --allow-read --allow-write https://deno.land/x/[email protected]/index.ts ~sourceFilename~ ~goalFilename~ | ||
* ``` | ||
* or | ||
* ``` | ||
import { convert } from 'https://deno.land/x/[email protected]/index.ts'; | ||
convert(~sourceFilename1~ ~goalFilename1~); | ||
(~sourceFilename2~ ~goalFilename2~); | ||
* ``` | ||
* | ||
* <en_us> | ||
* Created on Wed Jan 10 2024 16:56:00 | ||
* Feature: Translate file content from Simplified Chinese to Traditional Chinese.</en_us> | ||
* | ||
* <zh_cn> | ||
* 创建:2024年1月10日 16:56:00 | ||
* 功能:翻译文件中的简体中文到繁体中文。 | ||
* </zh_cn> | ||
* | ||
* <zh_tw> | ||
* 創建:2024年1月10日 16:56:00 | ||
* 功能:翻譯文件中的簡體中文到繁體中文。 | ||
* </zh_tw> | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.convert = void 0; | ||
const index_ts_1 = require("https://deno.land/x/[email protected]/index.ts"); | ||
const mod_ts_1 = require("https://deno.land/[email protected]/assert/mod.ts"); | ||
/** | ||
* <en_us>Convert Simplified Chinese to Traditional Chinese in a file</en_us> | ||
* <zh_cn>转换文件中的简体中文到繁体中文</zh_cn> | ||
* <zh_tw>轉換檔案中的簡體中文到繁體中文</zh_tw> | ||
* | ||
* @param sourceFilename string <en_us>Original document, including simplified Chinese</en_us><zh_cn>原始文件,含简体中文</zh_cn><zh_tw>原始文件,含簡體中文</zh_tw> | ||
* @param goalFilename string <en_us>Target traditional Chinese file</en_us><zh_cn>目标繁体文件</zh_cn><zh_tw>目標繁體文件</zh_tw> | ||
* | ||
* @returns boolean <en_us>Conversion is successful or not.</en_us><zh_cn>转换成功与否</zh_cn><zh_tw>轉換成功與否</zh_tw> | ||
*/ | ||
function convert(sourceFilename, goalFilename) { | ||
const FILE_WRITE_MODE = { mode: 0o777 }; | ||
try { | ||
const fileInfo = Deno.statSync(sourceFilename); | ||
mod_ts_1.assert(fileInfo.isFile); | ||
const SOURCE_CONTENT = Deno.readTextFileSync(sourceFilename); | ||
Deno.writeTextFileSync(goalFilename, index_ts_1.cn2tw(SOURCE_CONTENT), FILE_WRITE_MODE); | ||
return true; | ||
} | ||
catch (e) { | ||
console.error(e); | ||
return false; | ||
} | ||
} | ||
exports.convert = convert; | ||
(() => { | ||
const START_DATE = new Date(); | ||
const [source, goal] = Deno.args; | ||
console.log(convert(source, goal)); | ||
const END_DATE = new Date(); | ||
const USED_MILLISECONDS = END_DATE.getTime() - START_DATE.getTime(); | ||
console.log('Used', USED_MILLISECONDS, 'milliseconds, it is equivalent to ', parseFloat((USED_MILLISECONDS / 1000).toFixed(4))); | ||
})(); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"imports": { | ||
"/": "./", | ||
"./": "./", | ||
"fmt/": "https://deno.land/[email protected]/fmt/" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* <en_us>Convert Simplified Chinese to Traditional Chinese in a file</en_us> | ||
* <zh_cn>转换文件中的简体中文到繁体中文</zh_cn> | ||
* <zh_tw>轉換檔案中的簡體中文到繁體中文</zh_tw> | ||
* | ||
* @param sourceFilename string <en_us>Original document, including simplified Chinese</en_us><zh_cn>原始文件,含简体中文</zh_cn><zh_tw>原始文件,含簡體中文</zh_tw> | ||
* @param goalFilename string <en_us>Target traditional Chinese file</en_us><zh_cn>目标繁体文件</zh_cn><zh_tw>目標繁體文件</zh_tw> | ||
* | ||
* @returns boolean <en_us>Conversion is successful or not.</en_us><zh_cn>转换成功与否</zh_cn><zh_tw>轉換成功與否</zh_tw> | ||
*/ | ||
export declare function convert(sourceFilename: string, goalFilename: string): boolean; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright (c) 2024 [email protected] | ||
* index.ts | ||
* | ||
* Usage: ``` | ||
deno run --allow-run --allow-read --allow-write https://deno.land/x/[email protected]/index.ts ~sourceFilename~ ~goalFilename~ | ||
* ``` | ||
* or | ||
* ``` | ||
import { convert } from 'https://deno.land/x/[email protected]/index.ts'; | ||
convert(~sourceFilename1~ ~goalFilename1~); | ||
(~sourceFilename2~ ~goalFilename2~); | ||
* ``` | ||
* | ||
* <en_us> | ||
* Created on Wed Jan 10 2024 16:56:00 | ||
* Feature: Translate file content from Simplified Chinese to Traditional Chinese.</en_us> | ||
* | ||
* <zh_cn> | ||
* 创建:2024年1月10日 16:56:00 | ||
* 功能:翻译文件中的简体中文到繁体中文。 | ||
* </zh_cn> | ||
* | ||
* <zh_tw> | ||
* 創建:2024年1月10日 16:56:00 | ||
* 功能:翻譯文件中的簡體中文到繁體中文。 | ||
* </zh_tw> | ||
*/ | ||
|
||
import { cn2tw } from 'https://deno.land/x/[email protected]/index.ts'; | ||
import { assert } from 'https://deno.land/[email protected]/assert/mod.ts'; | ||
|
||
/** | ||
* <en_us>Convert Simplified Chinese to Traditional Chinese in a file</en_us> | ||
* <zh_cn>转换文件中的简体中文到繁体中文</zh_cn> | ||
* <zh_tw>轉換檔案中的簡體中文到繁體中文</zh_tw> | ||
* | ||
* @param sourceFilename string <en_us>Original document, including simplified Chinese</en_us><zh_cn>原始文件,含简体中文</zh_cn><zh_tw>原始文件,含簡體中文</zh_tw> | ||
* @param goalFilename string <en_us>Target traditional Chinese file</en_us><zh_cn>目标繁体文件</zh_cn><zh_tw>目標繁體文件</zh_tw> | ||
* | ||
* @returns boolean <en_us>Conversion is successful or not.</en_us><zh_cn>转换成功与否</zh_cn><zh_tw>轉換成功與否</zh_tw> | ||
*/ | ||
export function convert(sourceFilename: string, goalFilename: string): boolean { | ||
const FILE_WRITE_MODE = { mode: 0o777 }; | ||
try { | ||
const fileInfo = Deno.statSync(sourceFilename); | ||
assert(fileInfo.isFile); | ||
|
||
const SOURCE_CONTENT = Deno.readTextFileSync(sourceFilename); | ||
Deno.writeTextFileSync(goalFilename, cn2tw(SOURCE_CONTENT), FILE_WRITE_MODE); | ||
|
||
return true; | ||
} catch (e) { | ||
console.error(e); | ||
return false; | ||
} | ||
} | ||
|
||
(() => { | ||
const START_DATE = new Date(); | ||
|
||
const [source, goal] = Deno.args; | ||
console.log(convert(source, goal)); | ||
|
||
const END_DATE = new Date(); | ||
const USED_MILLISECONDS: number = END_DATE.getTime() - START_DATE.getTime(); | ||
console.log( | ||
'Used', | ||
USED_MILLISECONDS, | ||
'milliseconds, it is equivalent to ', | ||
parseFloat((USED_MILLISECONDS / 1000).toFixed(4)), | ||
); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2016", | ||
"module": "commonjs", | ||
"outDir": "./dist/", | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true | ||
} | ||
} |