Commit 40cc2454 authored by Chunchi Che's avatar Chunchi Che

fix localStorage

parent f87ef015
Pipeline #19941 passed with stages
in 5 minutes and 56 seconds
...@@ -4,13 +4,25 @@ export async function initStrings() { ...@@ -4,13 +4,25 @@ export async function initStrings() {
const strings = ( const strings = (
await axios.get<string>(`ygopro-database/locales/zh-CN/strings.conf`) await axios.get<string>(`ygopro-database/locales/zh-CN/strings.conf`)
).data; ).data;
localStorage.setItem("ygo-strings", strings);
const lineIter = strings.split("\n");
for (const line of lineIter) {
if (!line.startsWith("#") && line !== "") {
let [region, code, value] = line.split(" ", 3);
localStorage.setItem(`${region}_${code}`, value);
}
}
} }
export async function fetchStrings( export async function fetchStrings(
region: string, region: string,
id: number id: number,
local?: boolean
): Promise<string> { ): Promise<string> {
if (local) {
return localStorage.getItem(`${region}_${id}`) || "";
}
return ( return (
await axios.get<string>(`http://localhost:3030/strings/${region}_${id}`) await axios.get<string>(`http://localhost:3030/strings/${region}_${id}`)
).data; ).data;
......
...@@ -16,7 +16,7 @@ export const fetchCommonHintMeta = createAsyncThunk( ...@@ -16,7 +16,7 @@ export const fetchCommonHintMeta = createAsyncThunk(
const player = param[0]; const player = param[0];
const hintData = param[1]; const hintData = param[1];
const hintMeta = await fetchStrings("!system", hintData); const hintMeta = await fetchStrings("!system", hintData, true);
const response: [number, string] = [player, hintMeta]; const response: [number, string] = [player, hintMeta];
return response; return response;
......
...@@ -31,7 +31,7 @@ export const fetchYesNoMeta = createAsyncThunk( ...@@ -31,7 +31,7 @@ export const fetchYesNoMeta = createAsyncThunk(
cardLocation: ygopro.CardLocation cardLocation: ygopro.CardLocation
) => string; ) => string;
}) => { }) => {
const desc = await fetchStrings("!system", param.descCode); const desc = await fetchStrings("!system", param.descCode, true);
const meta = await fetchCard(param.code, true); const meta = await fetchCard(param.code, true);
// TODO: 国际化文案 // TODO: 国际化文案
......
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