From b455e63da75aa71eea00adc9349d7b456664fbcd Mon Sep 17 00:00:00 2001 From: taichan <40626578+tai-cha@users.noreply.github.com> Date: Thu, 26 Jun 2025 08:26:44 +0900 Subject: chore(frontend): 開発モード時に言語ファイルの変更を自動で反映するように (#16215) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(frontend): 開発モード時に言語ファイルの変更を自動で反映するように * fix message * naming * SPDX --- packages/frontend/lib/vite-plugin-watch-locales.ts | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 packages/frontend/lib/vite-plugin-watch-locales.ts (limited to 'packages/frontend/lib') diff --git a/packages/frontend/lib/vite-plugin-watch-locales.ts b/packages/frontend/lib/vite-plugin-watch-locales.ts new file mode 100644 index 0000000000..8e209d27bd --- /dev/null +++ b/packages/frontend/lib/vite-plugin-watch-locales.ts @@ -0,0 +1,36 @@ +/* + * SPDX-FileCopyrightText: syuilo and misskey-project + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import path from 'node:path' +import locales from '../../../locales/index.js'; + +const localesDir = path.resolve(__dirname, '../../../locales') + +/** + * 外部ファイルを監視し、必要に応じてwebSocketでメッセージを送るViteプラグイン + * @returns {import('vite').Plugin} + */ +export default function pluginWatchLocales() { + return { + name: 'watch-locales', + + configureServer(server) { + const localeYmlPaths = Object.keys(locales).map(locale => path.join(localesDir, `${locale}.yml`)); + + // watcherにパスを追加 + server.watcher.add(localeYmlPaths); + + server.watcher.on('change', (filePath) => { + if (localeYmlPaths.includes(filePath)) { + server.ws.send({ + type: 'custom', + event: 'locale-update', + data: filePath.match(/([^\/]+)\.yml$/)?.[1] || null, + }) + } + }); + }, + }; +} -- cgit v1.2.3-freya