From ce708b03aa418c2a0bc9c66abd08ffb880c963c4 Mon Sep 17 00:00:00 2001 From: xeltica Date: Fri, 24 Sep 2021 02:27:46 +0900 Subject: [PATCH] wip --- src/common/default-template.ts | 11 ----------- src/frontend/App.tsx | 21 ++++++++++++++++++++- src/frontend/components/SettingPage.tsx | 3 ++- src/frontend/init.tsx | 17 ----------------- src/frontend/langs/en_US.json5 | 1 + src/frontend/langs/ja_JP.json5 | 1 + src/frontend/misc/welcome-message.ts | 8 -------- 7 files changed, 24 insertions(+), 38 deletions(-) delete mode 100644 src/common/default-template.ts delete mode 100644 src/frontend/misc/welcome-message.ts diff --git a/src/common/default-template.ts b/src/common/default-template.ts deleted file mode 100644 index 4167a68..0000000 --- a/src/common/default-template.ts +++ /dev/null @@ -1,11 +0,0 @@ -/** - * デフォルトの投稿用テンプレート - */ -export const defaultTemplate = `昨日のMisskeyの活動は - -ノート: {notesCount}({notesDelta}) -フォロー : {followingCount}({followingDelta}) -フォロワー :{followersCount}({followersDelta}) - -でした。 -{url}`; diff --git a/src/frontend/App.tsx b/src/frontend/App.tsx index f8852ed..40f35d1 100644 --- a/src/frontend/App.tsx +++ b/src/frontend/App.tsx @@ -2,6 +2,8 @@ import React, { useState, useEffect, useCallback } from 'react'; import { BrowserRouter, Link, Route, Switch, useLocation } from 'react-router-dom'; import { Provider } from 'react-redux'; import { useTranslation } from 'react-i18next'; +import i18n from 'i18next'; +import { initReactI18next } from 'react-i18next'; import { IndexPage } from './pages'; import { RankingPage } from './pages/ranking'; @@ -10,11 +12,28 @@ import { TermPage } from './pages/term'; import { store, useSelector } from './store'; import { ModalComponent } from './Modal'; import { ActualTheme } from './misc/theme'; -import { ErrorCode } from '../common/types/error-code'; +import { getBrowserLanguage, resources } from './langs'; +import { LOCALSTORAGE_KEY_LANG } from './const'; import 'xeltica-ui/dist/css/xeltica-ui.min.css'; import './style.scss'; +document.body.classList.add('dark'); + +if (!localStorage[LOCALSTORAGE_KEY_LANG]) { + localStorage[LOCALSTORAGE_KEY_LANG] = getBrowserLanguage(); +} + +i18n + .use(initReactI18next) + .init({ + resources, + lng: localStorage[LOCALSTORAGE_KEY_LANG], + interpolation: { + escapeValue: false // react already safes from xss + } + }); + const AppInner : React.VFC = () => { const $location = useLocation(); diff --git a/src/frontend/components/SettingPage.tsx b/src/frontend/components/SettingPage.tsx index df2e02e..71f000c 100644 --- a/src/frontend/components/SettingPage.tsx +++ b/src/frontend/components/SettingPage.tsx @@ -3,7 +3,6 @@ import { alertModes } from '../../common/types/alert-mode'; import { IUser } from '../../common/types/user'; import { Visibility } from '../../common/types/visibility'; import { useGetSessionQuery } from '../services/session'; -import { defaultTemplate } from '../../common/default-template'; import { Card } from './Card'; import { Theme, themes } from '../misc/theme'; import { API_ENDPOINT, LOCALSTORAGE_KEY_TOKEN } from '../const'; @@ -141,6 +140,8 @@ export const SettingPage: React.VFC = () => { })); }, [dispatch]); + const defaultTemplate = t('_template.default'); + return session.isLoading || !data ? (
) : ( diff --git a/src/frontend/init.tsx b/src/frontend/init.tsx index b8fefe8..588b8ef 100644 --- a/src/frontend/init.tsx +++ b/src/frontend/init.tsx @@ -1,23 +1,6 @@ import * as React from 'react'; import * as ReactDOM from 'react-dom'; -import i18n from 'i18next'; -import { initReactI18next } from 'react-i18next'; import { App } from './App'; -import { getBrowserLanguage, resources } from './langs'; - -document.body.classList.add('dark'); - - -i18n - .use(initReactI18next) - .init({ - resources, - lng: localStorage['lang'] ?? getBrowserLanguage(), - interpolation: { - escapeValue: false // react already safes from xss - } - }); - ReactDOM.render(, document.getElementById('app')); diff --git a/src/frontend/langs/en_US.json5 b/src/frontend/langs/en_US.json5 index 6a12d14..23a022f 100644 --- a/src/frontend/langs/en_US.json5 +++ b/src/frontend/langs/en_US.json5 @@ -97,6 +97,7 @@ _template: { description: "Customize template of your alert.", description2: "Hashtag '#misshaialert' will be appended regardless of the template.", + default: "My Misskey activity yesterday was:\n\nNotes: {notesCount}({notesDelta})\nFollowing: {followingCount}({followingDelta})\nFollowers: {followersCount}({followersDelta})\n\n{url}", }, _error: { sorry: "Something went wrong. Please retry again.", diff --git a/src/frontend/langs/ja_JP.json5 b/src/frontend/langs/ja_JP.json5 index 1552860..15a6410 100644 --- a/src/frontend/langs/ja_JP.json5 +++ b/src/frontend/langs/ja_JP.json5 @@ -97,6 +97,7 @@ _template: { description: "アラートの自動投稿をカスタマイズできます。", description2: "ハッシュタグ #misshaialert は、テンプレートに関わらず自動付与されます。", + default: "昨日のMisskeyの活動は\n\nノート: {notesCount}({notesDelta})\nフォロー : {followingCount}({followingDelta})\nフォロワー :{followersCount}({followersDelta})\n\nでした。\n{url}", }, _error: { sorry: "問題が発生しました。お手数ですが、やり直してください。", diff --git a/src/frontend/misc/welcome-message.ts b/src/frontend/misc/welcome-message.ts deleted file mode 100644 index b55e11f..0000000 --- a/src/frontend/misc/welcome-message.ts +++ /dev/null @@ -1,8 +0,0 @@ -export const welcomeMessage = [ - 'ついついノートしすぎていませんか?', - 'Misskey, しすぎていませんか?', - '今日、何ノート書いた?', - '10000 ノートは初心者、そう思っていませんか?', - '息するように Misskey、そんなあなたへ。', - 'あなたは真の Misskey 廃人ですか?', -]; \ No newline at end of file