[+] More i18n

pull/23/head
Azalea 2024-03-06 10:13:08 -05:00
parent 3faa5b2f52
commit 16f6acf8fc
4 changed files with 28 additions and 14 deletions

View File

@ -16,9 +16,9 @@ if (navigator.language.startsWith('zh')) {
lang = 'zh' lang = 'zh'
} }
export function t(key: keyof LocalizedMessages, variables?: { [index: string]: string }) { export function t(key: keyof LocalizedMessages, variables?: { [index: string]: any }) {
if (variables) { if (variables) {
return msgs[lang][key].replace(/\${(.*?)}/g, (_: string, v: string | number) => variables[v]) return msgs[lang][key].replace(/\${(.*?)}/g, (_: string, v: string | number) => variables[v] + "")
} }
return msgs[lang][key] return msgs[lang][key]
} }

View File

@ -1,6 +1,7 @@
export const EN_REF_USER = { export const EN_REF_USER = {
'UserHome.ServerRank': 'Server Rank', 'UserHome.ServerRank': 'Server Rank',
'UserHome.Rating': 'DX Rating', 'UserHome.DXRating': 'DX Rating',
'UserHome.Rating': 'Rating',
'UserHome.Statistics': 'Statistics', 'UserHome.Statistics': 'Statistics',
'UserHome.Accuracy': 'Accuracy', 'UserHome.Accuracy': 'Accuracy',
'UserHome.DXScore': 'DX Score', 'UserHome.DXScore': 'DX Score',
@ -10,7 +11,12 @@ export const EN_REF_USER = {
'UserHome.FirstSeen': 'First Seen', 'UserHome.FirstSeen': 'First Seen',
'UserHome.LastSeen': 'Last Seen', 'UserHome.LastSeen': 'Last Seen',
'UserHome.Version': 'Last Version', 'UserHome.Version': 'Last Version',
'UserHome.RecentScores': 'Recent Scores' 'UserHome.RecentScores': 'Recent Scores',
'UserHome.NoData': 'No data in the past ${days} days',
'UserHome.Game.Mai2': "Mai",
'UserHome.Game.Chu3': "Chuni",
'UserHome.Game.Ongeki': "Ongeki",
'UserHome.UnknownSong': "(unknown song)",
} }
export const EN_REF_Welcome = { export const EN_REF_Welcome = {

View File

@ -2,17 +2,23 @@ import { EN_REF_USER, type EN_REF_Welcome } from "./en_ref";
const zhUser: typeof EN_REF_USER = { const zhUser: typeof EN_REF_USER = {
'UserHome.ServerRank': '服务器排名', 'UserHome.ServerRank': '服务器排名',
'UserHome.Rating': 'DX B50分', 'UserHome.DXRating': 'DX B50',
'UserHome.Rating': '评分',
'UserHome.Statistics': '统计数据', 'UserHome.Statistics': '统计数据',
'UserHome.Accuracy': '准确', 'UserHome.Accuracy': '准确',
'UserHome.DXScore': 'DX 得分', 'UserHome.DXScore': 'DX 得分',
'UserHome.PlayActivity': '游戏活动', 'UserHome.PlayActivity': '游戏活动',
'UserHome.Plays': '出勤次', 'UserHome.Plays': '出勤次',
'UserHome.PlayTime': '出勤时间', 'UserHome.PlayTime': '游玩时间',
'UserHome.FirstSeen': '发现新大陆', 'UserHome.FirstSeen': '发现新大陆',
'UserHome.LastSeen': '上次出勤', 'UserHome.LastSeen': '上次出勤',
'UserHome.Version': '最新最热否', 'UserHome.Version': '最新最热否',
'UserHome.RecentScores': '我的战绩' 'UserHome.RecentScores': '成绩',
'UserHome.NoData': '过去 ${days} 天内没有玩过',
'UserHome.Game.Mai2': "舞萌",
'UserHome.Game.Chu3': "中二",
'UserHome.Game.Ongeki': "音击",
'UserHome.UnknownSong': "(未知曲目)",
} }
const zhWelcome: typeof EN_REF_Welcome = { const zhWelcome: typeof EN_REF_Welcome = {

View File

@ -12,6 +12,8 @@
import Icon from "@iconify/svelte"; import Icon from "@iconify/svelte";
import {t} from "../libs/i18n"; import {t} from "../libs/i18n";
const TREND_DAYS = 60
registerChart() registerChart()
export let username: string; export let username: string;
@ -39,7 +41,7 @@
console.log(user) console.log(user)
console.log(trend) console.log(trend)
const minDate = moment().subtract(60, 'days').format("YYYY-MM-DD") const minDate = moment().subtract(TREND_DAYS, 'days').format("YYYY-MM-DD")
d = {user, d = {user,
trend: trend.filter(it => it.date >= minDate), trend: trend.filter(it => it.date >= minDate),
recent: user.recent.map(it => {return {...music[it.musicId], ...it}}) recent: user.recent.map(it => {return {...music[it.musicId], ...it}})
@ -50,7 +52,7 @@
}) })
}).catch((e) => error = e.message); }).catch((e) => error = e.message);
const games = {chu3: 'Chuni', mai2: 'Mai', ongeki: 'Ongeki'} const games = {chu3: t("UserHome.Game.Chu3"), mai2: t("UserHome.Game.Mai2"), ongeki: t("UserHome.Game.Ongeki")}
const titleText = games[game] const titleText = games[game]
</script> </script>
@ -79,7 +81,7 @@
<div class="chart"> <div class="chart">
<div class="info-top"> <div class="info-top">
<div class="rating"> <div class="rating">
<span>{game === 'mai2' ? t("UserHome.Rating"): 'Rating'}</span> <span>{game === 'mai2' ? t("UserHome.DXRating"): t("UserHome.Rating")}</span>
<span>{d.user.rating.toLocaleString()}</span> <span>{d.user.rating.toLocaleString()}</span>
</div> </div>
@ -93,7 +95,7 @@
<!-- ChartJS cannot be fully responsive unless there is a parent div that's independent from its size and helps it determine its size --> <!-- ChartJS cannot be fully responsive unless there is a parent div that's independent from its size and helps it determine its size -->
<div class="chartjs-box-reference"> <div class="chartjs-box-reference">
{#if d.trend.length === 0} {#if d.trend.length === 0}
<div class="no-data">No data in the past 60 days</div> <div class="no-data">{t("UserHome.NoData", { days: TREND_DAYS })}</div>
{:else} {:else}
<Line data={{ <Line data={{
datasets: [ datasets: [
@ -191,7 +193,7 @@
<div class:alt={i % 2 === 0}> <div class:alt={i % 2 === 0}>
<img src={`${DATA_HOST}/d/${game}/music/00${r.musicId.toString().padStart(6, '0').substring(2)}.png`} alt="" on:error={coverNotFound} /> <img src={`${DATA_HOST}/d/${game}/music/00${r.musicId.toString().padStart(6, '0').substring(2)}.png`} alt="" on:error={coverNotFound} />
<div class="info"> <div class="info">
<div>{r.name ??"Unable find music"}</div> <div>{r.name ?? t("UserHome.UnknownSong")}</div>
<div> <div>
<span class={`lv level-${r.level === 10 ? 3 : r.level}`}> <span class={`lv level-${r.level === 10 ? 3 : r.level}`}>
{ r.notes?.[r.level === 10 ? 0 : r.level]?.lv?.toFixed(1) ?? r.level ?? '0'} { r.notes?.[r.level === 10 ? 0 : r.level]?.lv?.toFixed(1) ?? r.level ?? '0'}