-
Notifications
You must be signed in to change notification settings - Fork 124
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
9 changed files
with
108 additions
and
484 deletions.
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import getLangMsgData from '../store/lang-msg' | ||
|
||
export default async function transLangMsg(data, pathname) { | ||
if (!data.option || !data.option.langMsg) return data | ||
|
||
const msgs = data.option.langMsg | ||
const langMsgMap = await getLangMsgData() | ||
for (let key of Object.keys(msgs)) { | ||
const msg = langMsgMap.get(`${key}${msgs[key].msg}`) | ||
if (msg && msg.trans) { | ||
msgs[key].msg = msg.trans | ||
} | ||
} | ||
return data | ||
} |
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 @@ | ||
import fetchData from '../fetch' | ||
import { getLocalData, setLocalData } from './local-data' | ||
import parseCsv from '../utils/parseCsv' | ||
import sortKeywords from '../utils/sortKeywords' | ||
|
||
const langMsgMap = new Map() | ||
let loaded = false | ||
|
||
const nameWithScenario = (list, key = 'name') => { | ||
const newList = [] | ||
const keys = [] | ||
list.forEach(item => { | ||
const existIdx = keys.indexOf(item[key]) | ||
if (existIdx !== -1) { | ||
const obj = newList[existIdx] | ||
if (item.scenario) { | ||
obj[item.scenario] = item | ||
obj.scenarios.push(item.scenario) | ||
} else { | ||
obj.trans = item.trans | ||
obj.noun = !!item.noun | ||
} | ||
} else { | ||
const obj = { [key]: item[key], scenarios: [] } | ||
if (item.scenario) { | ||
obj[item.scenario] = item | ||
obj.scenarios.push(item.scenario) | ||
} else { | ||
obj.trans = item.trans | ||
obj.noun = !!item.noun | ||
} | ||
newList.push(obj) | ||
keys.push(item[key]) | ||
} | ||
}) | ||
return newList | ||
} | ||
|
||
const getLangMsgData = async () => { | ||
if (!loaded) { | ||
let langMsg = getLocalData('langMsg') | ||
if (!langMsg) { | ||
langMsg = await fetchData('/blhxfy/data/lang-msg.csv') | ||
setLocalData('langMsg', langMsg) | ||
} | ||
const list = parseCsv(langMsg) | ||
list.forEach(item => { | ||
if (item.id && item.id.trim()) { | ||
item.en && langMsgMap.set(`${item.id}${item.en}`, { | ||
trans: item.trans, | ||
en: item.en, | ||
jp: item.jp | ||
}) | ||
item.jp && langMsgMap.set(`${item.id}${item.jp}`, { | ||
trans: item.trans, | ||
en: item.en, | ||
jp: item.jp | ||
}) | ||
} | ||
}) | ||
loaded = true | ||
} | ||
return langMsgMap | ||
} | ||
|
||
export default getLangMsgData |
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
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
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,12 +1,12 @@ | ||
import CSV from 'papaparse' | ||
import CSV from 'comma-separated-values' | ||
|
||
const parseCsv = (str) => { | ||
try { | ||
return CSV.parse(str.replace(/^\ufeff/, ''), { header: true }).data | ||
return CSV.parse(str.replace(/^\ufeff/, ''), { header: true }) | ||
} catch (err) { | ||
console.error(err) | ||
return {} | ||
} | ||
} | ||
|
||
export default parseCsv | ||
export default parseCsv |
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,3 @@ | ||
{ | ||
"ver": "0.4.0" | ||
} |
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
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
Oops, something went wrong.