Commit a7e59324 authored by KesaubeEire's avatar KesaubeEire

feat: tag 汉化.

parent 93f8cf6d
......@@ -57,7 +57,7 @@ npm run build:prod
- [x] TAG
- [x] 展示
- [x] 搜索
- [ ] 汉化...
- [x] 汉化
- [x] 主题切换
- [x] 基础切换
- [x] localstorage 记忆
......
<script>
import Card from './components/card.svelte';
import { SvelteToast, toast } from '@zerodevx/svelte-toast';
import { _category, _env } from './stores';
import { _category, _env, _tagTrans } from './stores';
// -----------------------------
// 各种请求封装头 & 请求函数
......@@ -12,6 +12,12 @@
params: { method: 'GET' }
};
/**请求封装头 -> 获取 TAG 翻译*/
const getTranslatedTag = {
url: `${$_env}/tag_translation.json`,
params: { method: 'GET' }
};
/**请求封装头 -> 获取所有资料*/
const getContentsRequest = {
url: `${$_env}/query.php?action=get`,
......@@ -125,7 +131,7 @@
// -----------------------------
// NOTE: 初始化执行 -> 考虑用 onMount
// 初始化请求 -> 拉取所有分类
// TODO: 搞个记时, 每天一刷
// TODO: 搞个记时, 每天一刷 & 做一个主动更新的按钮
if (!$_category.length) {
createFetch(getLanguageCategory, data => {
if (process.env.APP_ENV === 'dev') console.log(data);
......@@ -133,6 +139,15 @@
});
}
// 初始化请求 -> 拉取tag翻译
// TODO: 搞个记时, 每天一刷 & 做一个主动更新的按钮
if (!$_tagTrans.length) {
createFetch(getTranslatedTag, data => {
if (process.env.APP_ENV === 'dev') console.log(data);
$_tagTrans = data;
});
}
// 初始化请求 -> 拉取全部条目
createFetch(getContentsRequest, data => {
if (process.env.APP_ENV === 'dev') console.log(data);
......
<script>
import { _tagTrans } from '../stores';
/**父属性: 主标题*/
export let title;
/**父属性: 副标题*/
......@@ -28,6 +30,12 @@
tags = raw_tags.slice(1, raw_tags.length - 1).split('|');
}
function getTransTag(tag) {
const res = $_tagTrans.filter(trans => trans.jp_tag_name == tag);
// if (res) console.log(res[0]);
return res[0]?.cn_tag_name;
}
// 图片错误 trigger
let _picError = false;
......@@ -103,7 +111,7 @@
on:click={p_searchTag(tag)}
on:keypress={() => {}}
>
{tag}
{getTransTag(tag) ?? tag}
</div>
{/each}
{/if}
......
......@@ -39,5 +39,8 @@ export const _theme = persistStore('_theme', "light");
/** 环境变量 */
export const _env = persistStore('_env', "");
/** 环境变量 */
export const _category = persistStore('_category', {});
\ No newline at end of file
/** 定时持久化: 分类 */
export const _category = persistStore('_category', {});
/** 定时持久化: TAG 翻译 */
export const _tagTrans = persistStore('_tagTrans', {});
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment