diff --git a/.babelrc b/.babelrc
index 9c5b821..d841a2c 100644
--- a/.babelrc
+++ b/.babelrc
@@ -4,6 +4,9 @@
"development": {
"presets": ["react-hmre"]
},
+ "production": {
+ "presets": ["es2015"]
+ },
"test": {
"presets": ["es2015"]
}
diff --git a/.npmignore b/.npmignore
new file mode 100644
index 0000000..f0f05eb
--- /dev/null
+++ b/.npmignore
@@ -0,0 +1,20 @@
+node_modules/
+.npmignore
+.gitignore
+.babelrc
+.eslintrc.json
+
+# demo
+webpack.config.dev.js
+webpack.config.prod.js
+devServer.js
+taupahji.config.js
+index.html
+demo/
+favicons/
+build/
+
+# unittest
+app-css-dnt-compiler.js
+test/
+.travis.yml
\ No newline at end of file
diff --git a/demo/index.js b/demo/index.js
new file mode 100644
index 0000000..575bbb9
--- /dev/null
+++ b/demo/index.js
@@ -0,0 +1,13 @@
+import React from "react";
+import { render } from "react-dom";
+import MyProvider from "../src";
+
+const root = document.getElementById("app");
+
+// tau_pah_ji or sia_siann_mih
+// min, hakka, or uan
+
+render(
+
+ , root,
+);
diff --git a/package.json b/package.json
index 0659283..cee71c2 100644
--- a/package.json
+++ b/package.json
@@ -1,18 +1,22 @@
{
- "name": "tau3_phah4-ji7",
+ "name": "ten1su4",
"version": "0.0.1",
- "description": "鬥拍字",
+ "description": "ten1su4",
"scripts": {
"start": "node devServer.js",
"test": "NODE_ENV=test mocha --compilers js:babel-register,css:app-css-dnt-compiler --recursive",
"check": "eslint --ext .js --ext .jsx src/ test/",
"reformat": "eslint --fix --ext .js --ext .jsx src/ test/",
- "build": "mkdir -p build;rm -f build/* && NODE_ENV=production webpack --config webpack.config.prod.js --bail && (echo 'xn--kpu3003h.xn--v0qr21b.xn--kpry57d' > build/CNAME) && cp index.html favicons/* build/ && cp index.html build/404.html",
- "deploy": "npm run build && gh-pages -d build/"
+ "clear": "mkdir -p build;rm -f build/*",
+ "build": "NODE_ENV=production webpack --config webpack.config.prod.js --bail && (echo 'xn--kpu3003h.xn--v0qr21b.xn--kpry57d' > build/CNAME) && cp index.html favicons/* build/ && cp index.html build/404.html",
+ "deploy": "npm run clear && npm run build && gh-pages -d build/",
+ "clear-lib": "rm -rf lib;mkdir -p lib",
+ "compile-lib": "NODE_ENV=production babel src --out-dir lib --copy-files",
+ "publish-lib": "npm run clear-lib && npm run compile-lib && npm publish"
},
"repository": {
"type": "git",
- "url": "https://github.com/sih4sing5hong5/tau3_phah4-ji7.git"
+ "url": "https://github.com/i3thuan5/ten1su4.git"
},
"keywords": [
"臺語",
@@ -21,13 +25,13 @@
"author": "薛丞宏",
"license": "MIT",
"bugs": {
- "url": "https://github.com/sih4sing5hong5/tau3_phah4-ji7/issues"
+ "url": "https://github.com/i3thuan5/ten1su4/issues"
},
- "homepage": "http://xn--jny.xn--v0qr21b.xn--kpry57d/",
+ "homepage": "https://xn--kpu3003h.xn--v0qr21b.xn--kpry57d/",
"dependencies": {
"bluebird": "^3.4.1",
"debug": "^2.2.0",
- "demo-ui": "^1.11.5",
+ "demo-ui": "^1.13.6",
"prop-types": "^15.5.8",
"react": "^15.5.4",
"react-dom": "^15.5.4",
@@ -41,6 +45,7 @@
"superagent-bluebird-promise": "^3.0.2"
},
"devDependencies": {
+ "babel-cli": "^6.24.1",
"babel-core": "^6.4.0",
"babel-eslint": "^7.2.3",
"babel-loader": "^6.2.1",
@@ -63,6 +68,8 @@
"file-loader": "^0.9.0",
"gh-pages": "^0.11.0",
"html-loader": "^0.4.3",
+ "jsdom": "^11.0.0",
+ "jsdom-global": "^3.0.2",
"json-loader": "^0.5.4",
"mocha": "^3.2.0",
"nock": "^9.0.11",
diff --git a/src/actions/index.js b/src/actions/index.js
index 283c79c..75bd446 100644
--- a/src/actions/index.js
+++ b/src/actions/index.js
@@ -4,7 +4,7 @@ import {
RECIEVE_HANLO,
RECIEVE_ERROR_HANLO,
} from "./action.type";
-import { 後端網址, 標漢字音標 } from "../後端網址";
+import API from "../api";
export const 請求遠端查詢 = (語句, 腔口) => ({
type: REQUEST_HANLO,
@@ -28,8 +28,10 @@ export const 遠端查詢發生錯誤 = (語句, 腔口, error) => ({
export const 遠端查詢 = (語句, 腔口) => (dispatch) => {
dispatch(請求遠端查詢(語句, 腔口));
+ const apiFunc = API.取得查詢函式();
+
return superagent
- .get(後端網址 + 標漢字音標)
+ .get(apiFunc())
.query({
查詢腔口: 腔口,
查詢語句: 語句.trim(),
diff --git a/src/api/index.js b/src/api/index.js
new file mode 100644
index 0000000..5980ea8
--- /dev/null
+++ b/src/api/index.js
@@ -0,0 +1,30 @@
+import config from "../config";
+
+const api = {};
+const self = api;
+
+api.網域 = () => ("https://服務.意傳.台灣/");
+
+api.標漢字音標 = () => `${self.網域()}標漢字音標`;
+
+api.正規化翻譯 = () => `${self.網域()}正規化翻譯`;
+
+api.語音合成 = ({ 腔口 = "", 分詞 = "" } = {}) =>
+ encodeURI(`${self.網域()}語音合成?` +
+ `查詢腔口=${腔口}&查詢語句=${分詞}`);
+
+api.取得查詢函式名稱 = (專案 = config.專案()) => {
+ switch (專案) {
+ case "寫啥物":
+ return "正規化翻譯";
+ case "鬥拍字":
+ return "標漢字音標";
+ default:
+ return null;
+ }
+};
+
+api.取得查詢函式 = (專案 = config.專案()) =>
+ api[self.取得查詢函式名稱(專案)];
+
+export default api;
diff --git a/src/config/index.js b/src/config/index.js
new file mode 100644
index 0000000..bcd7e2e
--- /dev/null
+++ b/src/config/index.js
@@ -0,0 +1,11 @@
+import config from "../../taupahji.config";
+
+const configGenerator = {
+ 專案: () => (config.專案),
+ 全部腔口: () => (config.腔口),
+ 預設腔口: () => (config.腔口[0]),
+ 範例查詢: () => (config.範例查詢),
+ 頁尾連結: () => (config.頁尾連結),
+};
+
+export default configGenerator;
diff --git a/src/index.js b/src/index.js
index f61b0ac..9a5b331 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,39 +1 @@
-import React from "react";
-import { render } from "react-dom";
-import { Router, Route, IndexRoute, browserHistory } from "react-router";
-import thunk from "redux-thunk";
-import { Provider } from "react-redux";
-import { createStore, applyMiddleware } from "redux";
-import createLogger from "redux-logger";
-import Debug from "debug";
-import 網站 from "./網站/網站";
-import 查 from "./頁/查/查.container";
-import reducer from "./reducers";
-
-Debug.enable("tau3:*");
-
-const root = document.getElementById("app");
-const middlewares = [thunk];
-if (process.env.NODE_ENV !== "production") {
- middlewares.push(createLogger);
-}
-
-const store = createStore(
- reducer,
- applyMiddleware(...middlewares),
-);
-
-render(
-
-
-
-
-
-
-
-
-
-
- ,
- root,
-);
+export default from "./providers";
diff --git a/src/providers/index.jsx b/src/providers/index.jsx
new file mode 100644
index 0000000..03dfb6b
--- /dev/null
+++ b/src/providers/index.jsx
@@ -0,0 +1,40 @@
+import React from "react";
+import { Router, Route, IndexRoute, browserHistory } from "react-router";
+import thunk from "redux-thunk";
+import { Provider } from "react-redux";
+import { createStore, applyMiddleware } from "redux";
+import createLogger from "redux-logger";
+import 網站 from "../網站/網站";
+import 查 from "../頁/查/查";
+import reducer from "../reducers";
+
+const getAppStore = () => {
+ const middlewares = [thunk];
+ if (process.env.NODE_ENV !== "production") {
+ middlewares.push(createLogger);
+ }
+ const store = createStore(
+ reducer,
+ applyMiddleware(...middlewares),
+ );
+ return store;
+};
+
+const MyProvider = () => {
+ const store = getAppStore();
+ return (
+
+
+
+
+
+
+
+
+
+
+
+ );
+};
+
+export default MyProvider;
diff --git "a/src/reducers/\346\237\245\350\251\242.js" "b/src/reducers/\346\237\245\350\251\242.js"
index 93a1586..a791294 100644
--- "a/src/reducers/\346\237\245\350\251\242.js"
+++ "b/src/reducers/\346\237\245\350\251\242.js"
@@ -4,18 +4,16 @@ import {
RECIEVE_ERROR_HANLO,
} from "../actions/action.type";
-const 初始state = {
+const 初始state = () => ({
語句: "",
- 腔口: "四縣腔",
+ 腔口: "",
正在查詢: false,
發生錯誤: false,
-};
+});
-const 查詢 = (state = 初始state, action) => {
+const 查詢 = (state = 初始state(), action) => {
switch (action.type) {
case REQUEST_HANLO:
-
- // 保留上一次的查詢結果
return {
...state,
語句: action.語句,
diff --git "a/src/reducers/\346\237\245\350\251\242\347\265\220\346\236\234.js" "b/src/reducers/\346\237\245\350\251\242\347\265\220\346\236\234.js"
index c6c30e6..568653a 100644
--- "a/src/reducers/\346\237\245\350\251\242\347\265\220\346\236\234.js"
+++ "b/src/reducers/\346\237\245\350\251\242\347\265\220\346\236\234.js"
@@ -3,21 +3,38 @@ import {
RECIEVE_ERROR_HANLO,
} from "../actions/action.type";
-const 初始state = {
+export const 正規化綜合標音 = (綜合標音 = []) => {
+ if (!綜合標音 || 綜合標音.length === 0) {
+ return [];
+ }
+ const first = 綜合標音[0];
+ const keys = Object.keys(first);
+ const newKeys = keys.filter(x => (
+ x !== "臺羅閏號調" && x !== "臺灣客話"
+ ));
+ return 綜合標音.map((t) => {
+ const result = {};
+ result.羅馬字 = t.臺羅閏號調 || t.臺灣客話;
+ newKeys.forEach((k) => { result[k] = t[k]; });
+ return result;
+ });
+};
+
+const 初始state = () => ({
結果語句: "",
- 結果腔口: "四縣腔",
+ 結果腔口: "",
分詞: "",
綜合標音: [],
-};
+});
-const 查詢結果 = (state = 初始state, action) => {
+const 查詢結果 = (state = 初始state(), action) => {
switch (action.type) {
case RECIEVE_HANLO:
return {
結果語句: action.語句,
結果腔口: action.腔口,
分詞: action.查詢結果.分詞,
- 綜合標音: action.查詢結果.綜合標音,
+ 綜合標音: 正規化綜合標音(action.查詢結果.綜合標音),
};
case RECIEVE_ERROR_HANLO:
return {
diff --git "a/src/utils/\350\244\207\350\243\275.js" "b/src/utils/\350\244\207\350\243\275.js"
new file mode 100644
index 0000000..e4aca93
--- /dev/null
+++ "b/src/utils/\350\244\207\350\243\275.js"
@@ -0,0 +1,22 @@
+const 計算複製內容 = (綜合標音 = []) => {
+ if (!綜合標音 || 綜合標音.length < 1) {
+ return 綜合標音;
+ }
+
+ return 綜合標音
+ .map((item) => {
+ const 漢字 = item.漢字.replace(/ /g, "");
+ return {
+ 漢字羅馬: [漢字, item.羅馬字].join("\n"),
+ 羅馬字: item.羅馬字,
+ 漢字,
+ };
+ })
+ .reduce((acc, item) => ({
+ 漢字羅馬: [acc.漢字羅馬, item.漢字羅馬].join("\n"),
+ 漢字: [acc.漢字, item.漢字].join("\n"),
+ 羅馬字: [acc.羅馬字, item.羅馬字].join("\n"),
+ }));
+};
+
+export default 計算複製內容;
diff --git "a/src/\345\205\203\347\264\240/\347\277\273\350\255\257/\347\277\273\350\255\257\347\265\220\346\236\234.jsx" "b/src/\345\205\203\347\264\240/\347\277\273\350\255\257/\347\277\273\350\255\257\347\265\220\346\236\234.jsx"
index ce10053..00ea963 100644
--- "a/src/\345\205\203\347\264\240/\347\277\273\350\255\257/\347\277\273\350\255\257\347\265\220\346\236\234.jsx"
+++ "b/src/\345\205\203\347\264\240/\347\277\273\350\255\257/\347\277\273\350\255\257\347\265\220\346\236\234.jsx"
@@ -1,33 +1,15 @@
import React from "react";
import PropTypes from "prop-types";
import {
+ Block,
ButtonStack,
CopyButton,
DownloadButton,
+ PlayButton,
意傳服務,
} from "demo-ui";
import Container漢羅列表 from "../顯示/漢羅列表.container";
-
-export const 計算複製內容 = (綜合標音 = []) => {
- if (!綜合標音 || 綜合標音.length < 1) {
- return 綜合標音;
- }
-
- return 綜合標音
- .map((item) => {
- const 漢字 = item.漢字.replace(/ /g, "");
- return {
- 漢字臺羅: [漢字, item.臺灣客話].join("\n"),
- 臺羅: item.臺灣客話,
- 漢字,
- };
- })
- .reduce((acc, item) => ({
- 漢字臺羅: [acc.漢字臺羅, item.漢字臺羅].join("\n"),
- 漢字: [acc.漢字, item.漢字].join("\n"),
- 臺羅: [acc.臺羅, item.臺羅].join("\n"),
- }));
-};
+import 計算複製內容 from "../../utils/複製";
class 翻譯結果 extends React.Component {
取得複製鈕群() {
@@ -36,7 +18,7 @@ class 翻譯結果 extends React.Component {
綜合標音 = 綜合標音 || [];
分詞 = 分詞 || "";
let 複製內容 = {};
- if (!正在查詢 && !發生錯誤) {
+ if (!正在查詢 && !發生錯誤 && 綜合標音.length > 0) {
複製內容 = 計算複製內容(綜合標音);
複製內容.分詞 = 分詞;
}
@@ -50,12 +32,31 @@ class 翻譯結果 extends React.Component {
return 複製鈕群;
}
+ 取得整段鈕群() {
+ let { 綜合標音, 分詞 } = this.props;
+ 綜合標音 = 綜合標音 || [];
+ if (綜合標音.length > 0) {
+ 分詞 = 分詞 || "";
+ const { 腔口 } = this.props;
+ const src = 意傳服務.語音合成({ 腔口, 分詞 });
+ return (
+
+
+ 整段下載
+
+
+ 整段播放
+
+
+ );
+ }
+ return null;
+ }
+
render() {
- const { 正在查詢, 發生錯誤, 腔口 } = this.props;
+ const { 正在查詢, 發生錯誤 } = this.props;
const 複製鈕群 = this.取得複製鈕群();
- let { 分詞 } = this.props;
- 分詞 = 分詞 || "";
- const src = 意傳服務.語音合成({ 腔口, 分詞 });
+ const 整段鈕群 = this.取得整段鈕群();
return (
{
@@ -73,9 +74,7 @@ class 翻譯結果 extends React.Component {
{複製鈕群}
-
- 整段下載
-
+ {整段鈕群}
@@ -92,7 +91,7 @@ class 翻譯結果 extends React.Component {
綜合標音: PropTypes.arrayOf(PropTypes.shape({
分詞: PropTypes.string.isRequired,
漢字: PropTypes.string.isRequired,
- 臺灣客話: PropTypes.string.isRequired,
+ 羅馬字: PropTypes.string.isRequired,
})),
};
diff --git "a/src/\345\205\203\347\264\240/\351\241\257\347\244\272/\346\274\242\347\276\205\345\210\227\350\241\250.jsx" "b/src/\345\205\203\347\264\240/\351\241\257\347\244\272/\346\274\242\347\276\205\345\210\227\350\241\250.jsx"
index 0e2de93..f2f2a17 100644
--- "a/src/\345\205\203\347\264\240/\351\241\257\347\244\272/\346\274\242\347\276\205\345\210\227\350\241\250.jsx"
+++ "b/src/\345\205\203\347\264\240/\351\241\257\347\244\272/\346\274\242\347\276\205\345\210\227\350\241\250.jsx"
@@ -19,7 +19,7 @@ class 漢羅列表 extends React.Component {
key={i}
src={src}
漢字={綜音.漢字}
- 臺羅閏號調={綜音.臺灣客話}/>
+ 羅馬字={綜音.羅馬字}/>
);
})}
@@ -30,7 +30,7 @@ class 漢羅列表 extends React.Component {
漢羅列表.propTypes = {
結果腔口: PropTypes.string.isRequired,
綜合標音: PropTypes.arrayOf(PropTypes.shape({
- 臺灣客話: PropTypes.string.isRequired,
+ 羅馬字: PropTypes.string.isRequired,
漢字: PropTypes.string.isRequired,
分詞: PropTypes.string.isRequired,
})).isRequired,
diff --git "a/src/\345\276\214\347\253\257\347\266\262\345\235\200.js" "b/src/\345\276\214\347\253\257\347\266\262\345\235\200.js"
deleted file mode 100644
index c202845..0000000
--- "a/src/\345\276\214\347\253\257\347\266\262\345\235\200.js"
+++ /dev/null
@@ -1,3 +0,0 @@
-export const 後端網址 = "https://服務.意傳.台灣/";
-export const 標漢字音標 = "標漢字音標";
-export const 語音合成 = "語音合成?查詢腔口=四縣腔&查詢語句=";
diff --git "a/src/\347\266\262\347\253\231/\347\266\262\347\253\231.jsx" "b/src/\347\266\262\347\253\231/\347\266\262\347\253\231.jsx"
index a3d76f8..f87f382 100644
--- "a/src/\347\266\262\347\253\231/\347\266\262\347\253\231.jsx"
+++ "b/src/\347\266\262\347\253\231/\347\266\262\347\253\231.jsx"
@@ -3,6 +3,7 @@ import PropTypes from "prop-types";
import { Layout } from "demo-ui";
import 頁頭 from "./頁頭";
import 頁尾 from "./頁尾";
+import config from "../config";
class 網站 extends React.Component {
@@ -16,8 +17,8 @@ class 網站 extends React.Component {
React.cloneElement(
this.props.children,
{
- 語句: ku || "Tai-gaˊ共下來𢯭手!",
- 腔: khiunn || "四縣腔",
+ 語句: ku || config.範例查詢(),
+ 腔: khiunn || config.預設腔口(),
},
)
}
diff --git "a/src/\347\266\262\347\253\231/\351\240\201\345\260\276.jsx" "b/src/\347\266\262\347\253\231/\351\240\201\345\260\276.jsx"
index 70b5b9f..3d5e661 100644
--- "a/src/\347\266\262\347\253\231/\351\240\201\345\260\276.jsx"
+++ "b/src/\347\266\262\347\253\231/\351\240\201\345\260\276.jsx"
@@ -1,25 +1,14 @@
import React from "react";
import { Footer } from "demo-ui";
+import config from "../config";
const 頁尾 = () => {
- const sites = [{
- title: "Facebook",
- url: "https://www.facebook.com/i3thuan5/",
- },
- {
- title: "Github",
- url: "https://github.com/i3thuan5/ten1su4",
- },
- {
- title: "意傳文化科技",
- url: "https://xn--v0qr21b.xn--kpry57d/",
- },
- {
- title: "語料來源",
- url: "https://github.com/sih4sing5hong5/tai5-uan5_gian5-gi2_hok8-bu7/wiki/Taiwanese-Corpus%E8%AA%9E%E6%96%99",
- }];
+ const sites = config.頁尾連結();
+ if (sites.length === 0) {
+ return null;
+ }
return (
-