diff --git a/apps/campus/src/bus/Bus.tsx b/apps/campus/src/bus/Bus.tsx index e498f9b01..54d943ccf 100644 --- a/apps/campus/src/bus/Bus.tsx +++ b/apps/campus/src/bus/Bus.tsx @@ -321,10 +321,10 @@ const Bus = (): JSX.Element => { const { t, i18n } = useTranslation() useEffect(() => { - i18n.changeLanguage(localStorage.getItem("wasedatime-lng")) + // i18n.changeLanguage(localStorage.getItem("wasedatime-lng")) }, []) - const lng = i18n.language + const lng = i18n.language || "en" const { wasedaStatus, nishiStatus } = getBusStatuses(date, lng, t) const wasedaStatusComponent = createStatusComponent(wasedaStatus, t) const nishiStatusComponent = createStatusComponent(nishiStatus, t) diff --git a/apps/campus/src/root.component.tsx b/apps/campus/src/root.component.tsx index eccd2e532..9ead446da 100644 --- a/apps/campus/src/root.component.tsx +++ b/apps/campus/src/root.component.tsx @@ -1,22 +1,12 @@ import React, { Suspense, useContext, useEffect } from "react" -import { Lang, LoadingSpinner, i18nConfig } from "wasedatime-ui" -import i18next from "i18next" +import { LoadingSpinner } from "wasedatime-ui" import { useTranslation } from "react-i18next" import { BrowserRouter, Routes, Route } from "react-router-dom" import App from "@app/App" -import translationEN from "@app/constants/locales/en/translation.json" -import translationJA from "@app/constants/locales/ja/translation.json" +import "@app/utils/i18n" import { ThemeContext, ThemeProvider } from "@app/utils/theme-context" -i18nConfig({ - i18n: i18next, - customTranslations: { - [Lang.EN]: translationEN, - [Lang.JA]: translationJA, - }, -}) - const LoadingSpinnerContainer = () => { const { theme } = useContext(ThemeContext) diff --git a/apps/campus/src/utils/i18n.ts b/apps/campus/src/utils/i18n.ts new file mode 100644 index 000000000..8041681b6 --- /dev/null +++ b/apps/campus/src/utils/i18n.ts @@ -0,0 +1,40 @@ +import { initReactI18next } from "react-i18next" +import i18next from "i18next" +import { getCoreTranslation, getI18nLanguageDetector, getI18nHttpBackend, Lang } from "wasedatime-ui" +import translationEN from "@app/constants/locales/en/translation.json" +import translationJA from "@app/constants/locales/ja/translation.json" + +const resources = { + [Lang.EN]: { + translation: { ...getCoreTranslation(Lang.EN), ...translationEN }, + }, + [Lang.JA]: { + translation: { ...getCoreTranslation(Lang.JA), ...translationJA }, + }, +} + +const detectorOptions = { + order: ["localStorage"], + lookupLocalStorage: "wasedatime-lng", + caches: ["localStorage"], +} + +i18next + .use(getI18nHttpBackend()) + .use(getI18nLanguageDetector()) + .use(initReactI18next) // passes i18n down to react-i18next + .init({ + resources, + fallbackLng: Lang.EN, + keySeparator: ".", + interpolation: { + // react already safes from xss + escapeValue: false, + }, + // Configure the withNamespaces / NamespacesConsumer to + // not render the content until needed namespaces are loaded. + // react: { + // wait: true, + // }, + detection: detectorOptions, + }) diff --git a/apps/campus/src/wasedatime-campus.ts b/apps/campus/src/wasedatime-campus.ts index 9a85869a9..e4d9b7081 100644 --- a/apps/campus/src/wasedatime-campus.ts +++ b/apps/campus/src/wasedatime-campus.ts @@ -1,22 +1,8 @@ import React from "react" - -import { Lang, i18nConfig } from "wasedatime-ui" -import i18next from "i18next" import ReactDOM from "react-dom" import singleSpaReact from "single-spa-react" - -import translationEN from "@app/constants/locales/en/translation.json" -import translationJA from "@app/constants/locales/ja/translation.json" import Root from "@app/root.component" -i18nConfig({ - i18n: i18next, - customTranslations: { - [Lang.EN]: translationEN, - [Lang.JA]: translationJA, - }, -}) - const lifecycles = singleSpaReact({ React, ReactDOM, diff --git a/apps/feeds/components/FeedLink.tsx b/apps/feeds/components/FeedLink.tsx index d9979cbdb..ed75fe792 100644 --- a/apps/feeds/components/FeedLink.tsx +++ b/apps/feeds/components/FeedLink.tsx @@ -113,7 +113,7 @@ const FeedLink = ({ name, feed, locale }: Props) => {
-=P&&W("invalid-input"),de=x(L.charCodeAt(ge++)),(de>=u||de>I((a-G)/Q))&&W("overflow"),G+=de*Q,ne=V<=O?c:V>=O+l?l:V-O,!(de =P&&H("invalid-input"),de=x(L.charCodeAt(pe++)),(de>=u||de>T((a-K)/Q))&&H("overflow"),K+=de*Q,ne=$<=O?c:$>=O+l?l:$-O,!(de0&&a>s&&(a=s);for(var u=0;u=0?(f=c.substr(0,l),d=c.substr(l+1)):(f=c,d=""),g=decodeURIComponent(f),h=decodeURIComponent(d),_I(i,g)?Array.isArray(i[g])?i[g].push(h):i[g]=[i[g],h]:i[g]=h}return i},Ai=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}},zI=function(e,t,n,r){return t=t||"&",n=n||"=",e===null&&(e=void 0),typeof e=="object"?Object.keys(e).map(function(i){var o=encodeURIComponent(Ai(i))+n;return Array.isArray(e[i])?e[i].map(function(s){return o+encodeURIComponent(Ai(s))}).join(t):o+encodeURIComponent(Ai(e[i]))}).join(t):r?encodeURIComponent(Ai(r))+n+encodeURIComponent(Ai(e)):""};Ei.decode=Ei.parse=kI,Ei.encode=Ei.stringify=zI;var PI=Go,un=LI,wn=ih;function cn(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}var UI=/^([a-z0-9.+-]+:)/i,RI=/:[0-9]*$/,FI=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,YI=["<",">",'"',"`"," ","\r",`
-`," "],BI=["{","}","|","\\","^","`"].concat(YI),ou=["'"].concat(BI),th=["%","/","?",";","#"].concat(ou),nh=["/","?","#"],QI=255,rh=/^[+a-z0-9A-Z_-]{0,63}$/,$I=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,WI={javascript:!0,"javascript:":!0},su={javascript:!0,"javascript:":!0},Cr={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},au=Ei;function ih(e,t,n){if(e&&un.isObject(e)&&e instanceof cn)return e;var r=new cn;return r.parse(e,t,n),r}cn.prototype.parse=function(e,t,n){if(!un.isString(e))throw new TypeError("Parameter 'url' must be a string, not "+typeof e);var r=e.indexOf("?"),i=r!==-1&&r
=55296&&K<=56319&&P
65535&&(F-=65536,P+=B(F>>>10&1023|55296),F=56320|F&1023),P+=B(F),P}).join("")}function x(L){return L-48<10?L-22:L-65<26?L-65:L-97<26?L-97:u}function N(L,F){return L+22+75*(L<26)-((F!=0)<<5)}function S(L,F,P){var q=0;for(L=P?T(L/d):L>>1,L+=T(L/F);L>I*l>>1;q+=u)L=T(L/I);return T(q+(I+1)*L/(L+f))}function U(L){var F=[],P=L.length,q,K=0,ee=h,O=g,re,J,pe,V,Q,$,de,ne,fe;for(re=L.lastIndexOf(p),re<0&&(re=0),J=0;J