From c5b8ff0c1f0f62e7d5dd84aca32380b6af9333b7 Mon Sep 17 00:00:00 2001 From: syuilo <4439005+syuilo@users.noreply.github.com> Date: Fri, 23 Aug 2024 12:32:23 +0900 Subject: [PATCH] wip --- packages/embed/src/components/I18n.vue | 51 ++++++++++++++++++++++++++ packages/embed/src/config.ts | 18 +++++++++ packages/embed/src/i18n.ts | 15 ++++++++ 3 files changed, 84 insertions(+) create mode 100644 packages/embed/src/components/I18n.vue create mode 100644 packages/embed/src/config.ts create mode 100644 packages/embed/src/i18n.ts diff --git a/packages/embed/src/components/I18n.vue b/packages/embed/src/components/I18n.vue new file mode 100644 index 0000000000..6b7723e6ac --- /dev/null +++ b/packages/embed/src/components/I18n.vue @@ -0,0 +1,51 @@ + + + + + diff --git a/packages/embed/src/config.ts b/packages/embed/src/config.ts new file mode 100644 index 0000000000..08f14dfdd8 --- /dev/null +++ b/packages/embed/src/config.ts @@ -0,0 +1,18 @@ +/* + * SPDX-FileCopyrightText: syuilo and misskey-project + * SPDX-License-Identifier: AGPL-3.0-only + */ + +const address = new URL(document.querySelector('meta[property="instance_url"]')?.content || location.href); +const siteName = document.querySelector('meta[property="og:site_name"]')?.content; + +export const host = address.host; +export const hostname = address.hostname; +export const url = address.origin; +export const apiUrl = location.origin + '/api'; +export const langs = _LANGS_; +const preParseLocale = miLocalStorage.getItem('locale'); +export const locale = preParseLocale ? JSON.parse(preParseLocale) : null; +export const instanceName = siteName === 'Misskey' || siteName == null ? host : siteName; +export const ui = miLocalStorage.getItem('ui'); +export const debug = miLocalStorage.getItem('debug') === 'true'; diff --git a/packages/embed/src/i18n.ts b/packages/embed/src/i18n.ts new file mode 100644 index 0000000000..10d6adbcd0 --- /dev/null +++ b/packages/embed/src/i18n.ts @@ -0,0 +1,15 @@ +/* + * SPDX-FileCopyrightText: syuilo and misskey-project + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import { markRaw } from 'vue'; +import type { Locale } from '../../../locales/index.js'; +import { locale } from '@/config.js'; +import { I18n } from '@/scripts/i18n.js'; + +export const i18n = markRaw(new I18n(locale)); + +export function updateI18n(newLocale: Locale) { + i18n.locale = newLocale; +}