Skip to content

Commit

Permalink
Merge 86300c1 into bd040df
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnychhsu committed Apr 17, 2019
2 parents bd040df + 86300c1 commit 8989019
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/i18n/traditional-chinese.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
40 changes: 40 additions & 0 deletions test/test_i18n_chinese.js
Original file line number Diff line number Diff line change
@@ -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 <johnny.chhsu01@gmail.com>
//
// 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();

0 comments on commit 8989019

Please sign in to comment.