From d75db01f14138ea660c4c519e37ab05228b39d13 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 26 Jul 2019 14:44:50 +0200 Subject: Add plugin translation system --- server/controllers/plugins.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'server/controllers/plugins.ts') diff --git a/server/controllers/plugins.ts b/server/controllers/plugins.ts index f5285ba3a..1caee9a29 100644 --- a/server/controllers/plugins.ts +++ b/server/controllers/plugins.ts @@ -1,11 +1,12 @@ import * as express from 'express' import { PLUGIN_GLOBAL_CSS_PATH } from '../initializers/constants' import { join } from 'path' -import { RegisteredPlugin } from '../lib/plugins/plugin-manager' +import { PluginManager, RegisteredPlugin } from '../lib/plugins/plugin-manager' import { servePluginStaticDirectoryValidator } from '../middlewares/validators/plugins' import { serveThemeCSSValidator } from '../middlewares/validators/themes' import { PluginType } from '../../shared/models/plugins/plugin.type' import { isTestInstance } from '../helpers/core-utils' +import { getCompleteLocale, is18nLocale } from '../../shared/models/i18n' const sendFileOptions = { maxAge: '30 days', @@ -18,6 +19,10 @@ pluginsRouter.get('/plugins/global.css', servePluginGlobalCSS ) +pluginsRouter.get('/plugins/translations/:locale.json', + getPluginTranslations +) + pluginsRouter.get('/plugins/:pluginName/:pluginVersion/static/:staticEndpoint(*)', servePluginStaticDirectoryValidator(PluginType.PLUGIN), servePluginStaticDirectory @@ -60,6 +65,19 @@ function servePluginGlobalCSS (req: express.Request, res: express.Response) { return res.sendFile(PLUGIN_GLOBAL_CSS_PATH, globalCSSOptions) } +function getPluginTranslations (req: express.Request, res: express.Response) { + const locale = req.params.locale + + if (is18nLocale(locale)) { + const completeLocale = getCompleteLocale(locale) + const json = PluginManager.Instance.getTranslations(completeLocale) + + return res.json(json) + } + + return res.sendStatus(404) +} + function servePluginStaticDirectory (req: express.Request, res: express.Response) { const plugin: RegisteredPlugin = res.locals.registeredPlugin const staticEndpoint = req.params.staticEndpoint -- cgit v1.2.3