From ba1e96db26927e0cd8a64f2bc593a920f01abd92 Mon Sep 17 00:00:00 2001 From: heimoshuiyu Date: Fri, 22 Jul 2022 11:52:06 +0800 Subject: [PATCH] add multi language support --- web/src/App.js | 216 ++++++++++++++++------------ web/src/component/AudioPlayer.js | 13 +- web/src/component/Database.js | 18 ++- web/src/component/EditReview.js | 14 +- web/src/component/EditTag.js | 22 +-- web/src/component/FeedbackPage.js | 15 +- web/src/component/FileDialog.js | 11 +- web/src/component/FileInfo.js | 42 +++--- web/src/component/FilesInFolder.js | 15 +- web/src/component/FilesTable.js | 7 +- web/src/component/FoldersTable.js | 7 +- web/src/component/GetRandomFiles.js | 8 +- web/src/component/Login.js | 16 ++- web/src/component/Manage.js | 39 +++-- web/src/component/ManageUser.js | 29 ++-- web/src/component/Register.js | 26 ++-- web/src/component/ReviewEntry.js | 15 +- web/src/component/ReviewPage.js | 5 +- web/src/component/SearchFiles.js | 14 +- web/src/component/SearchFolders.js | 14 +- web/src/component/Share.js | 10 +- web/src/component/Tags.js | 21 +-- web/src/component/UserProfile.js | 20 +-- web/src/translate/index.js | 44 ++++++ web/src/translate/zh_CN.js | 105 ++++++++++++++ 25 files changed, 494 insertions(+), 252 deletions(-) create mode 100644 web/src/translate/index.js create mode 100644 web/src/translate/zh_CN.js diff --git a/web/src/App.js b/web/src/App.js index ec5468a..5c1e2bf 100644 --- a/web/src/App.js +++ b/web/src/App.js @@ -19,105 +19,135 @@ import UserStatus from "./component/UserStatus"; import ReviewPage from "./component/ReviewPage"; import UserProfile from "./component/UserProfile"; import FeedbackPage from "./component/FeedbackPage"; -import { useState } from "react"; +import { useEffect, useState } from "react"; +import { Tr, langCodeContext, LANG_OPTIONS } from "./translate"; function App() { const [playingFile, setPlayingFile] = useState({}); const [user, setUser] = useState({}); + const [langCode, setLangCode] = useState("en_US"); + + // select language + useEffect(() => { + const browserCode = window.navigator.language; + for (const key in LANG_OPTIONS) { + for (const i in LANG_OPTIONS[key].matches) { + const code = LANG_OPTIONS[key].matches[i]; + if (code === browserCode) { + setLangCode(key); + return; + } + } + } + // fallback to english + setLangCode('en-US'); + }, []); + return (
- -
-

- logo - MSW Open Music Project - -

- -
-
- - } - /> - } - /> - } - /> - } - /> - } - /> - } - /> - } - /> - } - /> - } /> - } /> - } - /> - } - /> - } - /> - } - /> - } - /> - - } - /> - -
- -
+ + +
+

+ logo + MSW Open Music Project + +

+ +
+
+ + } + /> + } + /> + } + /> + } + /> + + } + /> + } + /> + } + /> + } + /> + } /> + } + /> + } + /> + } + /> + } + /> + } + /> + } + /> + + } + /> + +
+ +
+
); } diff --git a/web/src/component/AudioPlayer.js b/web/src/component/AudioPlayer.js index 8397ab4..6f10126 100644 --- a/web/src/component/AudioPlayer.js +++ b/web/src/component/AudioPlayer.js @@ -3,6 +3,7 @@ import { useNavigate } from "react-router"; import { CalcReadableFilesizeDetail } from "./Common"; import FfmpegConfig from "./FfmpegConfig"; import FileDialog from "./FileDialog"; +import { Tr } from "../translate"; function AudioPlayer(props) { // props.playingFile @@ -67,7 +68,7 @@ function AudioPlayer(props) { return (