|
@@ -1,4 +1,5 @@
|
|
|
import Cookies from "js-cookie";
|
|
import Cookies from "js-cookie";
|
|
|
|
|
+
|
|
|
import "moment/locale/zh-cn";
|
|
import "moment/locale/zh-cn";
|
|
|
import "moment/locale/zh-tw";
|
|
import "moment/locale/zh-tw";
|
|
|
import "moment/locale/es";
|
|
import "moment/locale/es";
|
|
@@ -13,48 +14,45 @@ import zhHant from "./zh-Hant";
|
|
|
|
|
|
|
|
const KEY = "locale";
|
|
const KEY = "locale";
|
|
|
|
|
|
|
|
-export const DEFAULT: string =
|
|
|
|
|
- process.env.REACT_APP_DEFAULT_LOCALE || "zh-Hans";
|
|
|
|
|
-export const LANGUAGES: string[] = process.env.REACT_APP_LANGUAGES?.split(
|
|
|
|
|
- ","
|
|
|
|
|
-) || ["en-US", "zh-Hans"];
|
|
|
|
|
|
|
+export const DEFAULT: string = process.env.REACT_APP_DEFAULT_LOCALE || "zh-Hans";
|
|
|
|
|
+export const LANGUAGES: string[] = process.env.REACT_APP_LANGUAGES?.split(",") || ["en-US", "zh-Hans"];
|
|
|
|
|
|
|
|
export const get = (): string => {
|
|
export const get = (): string => {
|
|
|
- return localStorage.getItem(KEY) || Cookies.get(KEY) || DEFAULT;
|
|
|
|
|
|
|
+ return localStorage.getItem(KEY) || Cookies.get(KEY) || DEFAULT;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
export const set = (lang: string, reload: boolean) => {
|
|
export const set = (lang: string, reload: boolean) => {
|
|
|
- Cookies.set(KEY, lang);
|
|
|
|
|
- localStorage.setItem(KEY, lang);
|
|
|
|
|
- if (reload) {
|
|
|
|
|
- window.location.reload();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ Cookies.set(KEY, lang);
|
|
|
|
|
+ localStorage.setItem(KEY, lang);
|
|
|
|
|
+ if (reload) {
|
|
|
|
|
+ window.location.reload();
|
|
|
|
|
+ }
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
export const remove = () => {
|
|
export const remove = () => {
|
|
|
- Cookies.remove(KEY);
|
|
|
|
|
- localStorage.removeItem(KEY);
|
|
|
|
|
|
|
+ Cookies.remove(KEY);
|
|
|
|
|
+ localStorage.removeItem(KEY);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
interface ILocale {
|
|
interface ILocale {
|
|
|
- messages: Record<string, string>;
|
|
|
|
|
|
|
+ messages: Record<string, string>;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const messages = (lang: string): ILocale => {
|
|
const messages = (lang: string): ILocale => {
|
|
|
- switch (lang) {
|
|
|
|
|
- case "en-US":
|
|
|
|
|
- return {
|
|
|
|
|
- messages: { ...enUS, ...languages },
|
|
|
|
|
- };
|
|
|
|
|
- case "zh-Hant":
|
|
|
|
|
- return {
|
|
|
|
|
- messages: { ...zhHant, ...languages },
|
|
|
|
|
- };
|
|
|
|
|
- default:
|
|
|
|
|
- return {
|
|
|
|
|
- messages: { ...zhHans, ...languages },
|
|
|
|
|
- };
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ switch (lang) {
|
|
|
|
|
+ case "en-US":
|
|
|
|
|
+ return {
|
|
|
|
|
+ messages: { ...enUS, ...languages },
|
|
|
|
|
+ };
|
|
|
|
|
+ case "zh-Hant":
|
|
|
|
|
+ return {
|
|
|
|
|
+ messages: { ...zhHant, ...languages },
|
|
|
|
|
+ };
|
|
|
|
|
+ default:
|
|
|
|
|
+ return {
|
|
|
|
|
+ messages: { ...zhHans, ...languages },
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
export default messages;
|
|
export default messages;
|