diff --git a/lib/i18n/traditional-chinese.js b/lib/i18n/traditional-chinese.js index 0a3acae55..ded8049cc 100644 --- a/lib/i18n/traditional-chinese.js +++ b/lib/i18n/traditional-chinese.js @@ -9,8 +9,26 @@ // See COPYING for details "use strict"; +var keys = [ + ["on", "開"],["off", "關"],["drip coffee","濾掛式 咖啡"],["espresso","義式 濃縮"],["latte","拿鐵"],["flat white", "牛奶 咖啡"],["white mocha","白摩卡"], + ["caramel mocha","星冰樂"],["mocha","摩卡"],["macchiato","瑪琪雅朵"],["caramel macchiato","白瑪琪雅朵"],["cappuccino","卡布其諾"],["americano","美式"], + ["heat","暖氣"],["cool","冷氣"],["track","歌曲"],["normal","普通"],["vibrate","振動"],["silent","靜音"],["auto","自動"],["away","不在"],["pool","共乘"],["select","uber 精選"], + ["suv","休旅車"],["assist","uber 關懷"],["best of youtube","熱門"],["recommended","推薦"],["paid","付費"],["music","音樂"],["comedy","喜劇"],["film and entertainment","電影 與 娛樂"], + ["gaming","遊戲"],["beauty and fashion","流行"],["from_tv","電視"],["automotive","汽車"],["animation","動畫"],["sports","動畫"],["diy","動手做"],["tech","科技"],["science","科學 與 自然"], + ["cooking","烹飪"],["causes","起因"],["news and politics","政治"],["lifestyle","生活 風格"],["raining","下雨"],["cloudy","多雲"],["sunny","晴天"],["snowy","下 雪"],["sleety","下 冰雹"], + ["drizzling","毛毛雨"],["windy","刮風"],["politics","政治"],["opinions","社論"],["local","地區"],["sports","運動"],["national","國家"],["world","國際"],["powerpost","焦點"], + ["capital weather gang","首都 天氣"],["morning mix","晨間 新聞"],["wonkblog"],["world news","世界 新聞"],["us business","美國 商業"],["business","商業"],["markets","市場"], + ["technology","科技"],["cat","貓"],["dog","狗"],["horse","馬"],["snail","蝸牛"],["year","年"],["yoda","尤達"],["shakespeare","莎士比亞"],["vulcan","瓦肯人"],["klingon","克林貢"], + ["viral","傳閱"],["rising","上升"],["uber_black","尊榮"] +]; + function postprocessSynthetic(sentence, program) { // We need a dummy postprocessSynthetic() here + keys.forEach(function(key) { + var re = new RegExp("\\b" + key[0] + "\\b", "g"); + if(sentence.match(re)) + sentence = sentence.replace(key[0], key[1]); + }); return sentence; } diff --git a/test/test_i18n_chinese.js b/test/test_i18n_chinese.js new file mode 100644 index 000000000..627f941bf --- /dev/null +++ b/test/test_i18n_chinese.js @@ -0,0 +1,40 @@ +// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*- +// +// This file is part of ThingEngine +// +// Copyright 2019 National Taiwan University +// +// Author: Johnny Hsu +// +// See COPYING for details +"use strict"; + +const assert = require('assert'); + +const zh_tw = require('../lib/i18n/traditional-chinese'); + +const SENTENCE_TEST_CASES = [ + ["給 我 一杯 drip coffee", "給 我 一杯 濾掛式 咖啡"], + ["給 我 一杯 white mocha", "給 我 一杯 白摩卡"], + ["幫 我 放 music", "幫 我 放 音樂"], + ["今天 天氣 是 raining", "今天 天氣 是 下雨"], + ["台北 的 天氣 cloudy", "台北 的 天氣 多雲"], + ["給 我 powerpost 版 新聞", "給 我 焦點 版 新聞"], + ["福斯 新聞 的 us business 新聞", "福斯 新聞 的 美國 商業 新聞"], + ["叫 一 輛 uber uber_black", "叫 一 輛 uber 尊榮"], +]; + +function testPostProcessSynthetic() { + for (let i = 0; i < SENTENCE_TEST_CASES.length; i++) { + let [original, processed] = SENTENCE_TEST_CASES[i]; + let result = zh_tw.postprocessSynthetic(original, ""); + assert.strictEqual(processed, result); + } +} + +async function main() { + testPostProcessSynthetic() +} +module.exports = main; +if (!module.parent) + main(); \ No newline at end of file