修改语言的匹配
This commit is contained in:
parent
d2c0f43151
commit
1e054bc8d8
14
README.md
14
README.md
|
@ -56,14 +56,16 @@ Chrome browser need start with the additional argument `--allow-file-access-from
|
|||
This is an Object for a language list item.
|
||||
```js
|
||||
{
|
||||
name:"English",
|
||||
i18n:"en",
|
||||
searchlist:["en","ja"],
|
||||
guideURL:id=>`http://www.puzzledragonx.com/en/monster.asp?n=${id}`
|
||||
name: "English",
|
||||
i18n: "en",
|
||||
i18n_RegExp: /^en/i,
|
||||
searchlist: ["en","ja"],
|
||||
guideURL: id=>`http://www.puzzledragonx.com/en/monster.asp?n=${id}`
|
||||
}
|
||||
```
|
||||
* `name` is the name shown in the list.
|
||||
* `i18n` is the language-tag for your language.
|
||||
* `name` is the showed name in the list.
|
||||
* `i18n` is the language-tag for your language. You need to make sure that the file names are the same.
|
||||
* `i18n_RegExp` is a *Regular Expressions* to match multiple languages (like `/^en/i` can match `en-US`, `en-CA` and `en-AU`).
|
||||
* `searchlist` is the search candidate list string order when you search monster in edit window.
|
||||
Currently only `ja`,`en`,`ko`,`cht`,`chs` languages.(See [monsters-info](monsters-info))
|
||||
* `guideURL` is a **Function(cardId,cardName)** to return game guide URL for your language.
|
||||
|
|
|
@ -1,20 +1,19 @@
|
|||
var languageList = [
|
||||
const languageList = [
|
||||
{
|
||||
name:"English",i18n:"en",searchlist:["en","ja"],
|
||||
guideURL:id=>`http://www.puzzledragonx.com/en/monster.asp?n=${id}` //or (id,name)=>`http://www.puzzledragonx.com/en/search.asp?q=${name}`
|
||||
},
|
||||
{
|
||||
name:"中文(繁體)",i18n:"zh-TW",searchlist:["cht","ja"],
|
||||
guideURL:id=>`http://pad.skyozora.com/pets/${id}`
|
||||
name:"中文(繁體)",i18n:"zh-TW",i18n_RegExp:/^zh-(?:hant-)?TW/i,searchlist:["cht","ja"],
|
||||
guideURL:id=>`https://pad.skyozora.com/pets/${id}`
|
||||
},
|
||||
{
|
||||
name:"中文(简体)技能解析",i18n:"zh-CN",searchlist:["chs","ja"],
|
||||
guideURL:id=>`http://pad.skyozora.com/pets/${id}`
|
||||
//guideURL:id=>{const url = new URL(location);url.search = '';url.searchParams.set("guide",1);url.searchParams.set("id",id); return url;}
|
||||
name:"中文(简体)技能解析",i18n:"zh-CN",i18n_RegExp:/^zh-(?:hans-)?/i,searchlist:["chs","ja"],
|
||||
guideURL:id=>`https://pad.skyozora.com/pets/${id}`
|
||||
},
|
||||
{
|
||||
name:"中文(简体)原版技能",i18n:"zh",searchlist:["chs","ja"],
|
||||
guideURL:id=>`http://pad.skyozora.com/pets/${id}`
|
||||
guideURL:id=>`https://pad.skyozora.com/pets/${id}`
|
||||
},
|
||||
{
|
||||
name:"日本語",i18n:"ja",searchlist:["ja"],
|
||||
|
|
15
script.js
15
script.js
|
@ -32,12 +32,15 @@ if (currentLanguage == undefined)
|
|||
const parameter_i18n = getQueryString("l") || getQueryString("lang"); //获取参数指定的语言
|
||||
const browser_i18n = (navigator.language || navigator.userLanguage); //获取浏览器语言
|
||||
currentLanguage = languageList.find(lang => { //筛选出符合的语言
|
||||
if (parameter_i18n) //如果已指定就用指定的语言
|
||||
return parameter_i18n.includes(lang.i18n);
|
||||
else //否则筛选浏览器默认语言
|
||||
return browser_i18n.includes(lang.i18n);
|
||||
}) ||
|
||||
languageList[0]; //没有找到指定语言的情况下,自动用第一个语言(英语)
|
||||
let searchCode = parameter_i18n || browser_i18n; //如果已指定就用指定的语言,否则筛选浏览器默认语言
|
||||
if (lang.i18n_RegExp)
|
||||
{
|
||||
return lang.i18n_RegExp.test(searchCode);
|
||||
}else
|
||||
{
|
||||
return searchCode.includes(lang.i18n);
|
||||
}
|
||||
}) || languageList[0]; //没有找到指定语言的情况下,自动用第一个语言(英语)
|
||||
//因为Script在Head里面,所以可以这里head已经加载好可以使用
|
||||
document.head.querySelector("#language-css").href = `languages/${currentLanguage.i18n}.css`;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue