Add plugin translation system
This commit is contained in:
parent
ee286591a5
commit
d75db01f14
18 changed files with 304 additions and 29 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue