Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
anqisoft committed Jan 10, 2024
1 parent 557000c commit b07879a
Show file tree
Hide file tree
Showing 14 changed files with 284 additions and 1 deletion.
39 changes: 38 additions & 1 deletion README.md
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>
2 changes: 2 additions & 0 deletions bat/buildDeclarationFiles.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cd..
tsc --declaration -p .\ -t es2020 --emitDeclarationOnly --outDir .
2 changes: 2 additions & 0 deletions bat/clearMinJs.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
@del /s/q "%CD%\..\dist\*.min.js"
27 changes: 27 additions & 0 deletions bat/compressJs.bat
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!
)
)
8 changes: 8 additions & 0 deletions bat/deno/bundle.bat
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
4 changes: 4 additions & 0 deletions bat/deno/fmt.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@ECHO OFF
deno fmt

pause
4 changes: 4 additions & 0 deletions bat/deno/lint.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@ECHO OFF
deno lint

pause
30 changes: 30 additions & 0 deletions deno.json
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": []
}
}
66 changes: 66 additions & 0 deletions dist/index.js
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)));
})();
1 change: 1 addition & 0 deletions dist/index.min.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions import_map.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"imports": {
"/": "./",
"./": "./",
"fmt/": "https://deno.land/[email protected]/fmt/"
}
}
11 changes: 11 additions & 0 deletions index.d.ts
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;
73 changes: 73 additions & 0 deletions index.ts
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)),
);
})();
11 changes: 11 additions & 0 deletions tsconfig.json
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
}
}

0 comments on commit b07879a

Please sign in to comment.