From 2a50997a7586976888826e2f8760010dad68eccb Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 2 Feb 2019 16:16:31 +0900 Subject: [PATCH] Fallback en-US --- src/server/web/docs.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/server/web/docs.ts b/src/server/web/docs.ts index 84dbe6f09..f823c308c 100644 --- a/src/server/web/docs.ts +++ b/src/server/web/docs.ts @@ -19,6 +19,14 @@ import endpoints from '../api/endpoints'; const locales = require('../../../locales'); import * as nestedProperty from 'nested-property'; +function getLang(lang: string): string { + if (['en-US', 'ja-JP'].includes(lang)) { + return lang; + } else { + return 'en-US'; + } +} + async function genVars(lang: string): Promise<{ [key: string]: any }> { const vars = {} as { [key: string]: any }; @@ -167,7 +175,7 @@ router.get('/assets/*', async ctx => { }); router.get('/*/api/endpoints/*', async ctx => { - const lang = ctx.params[0]; + const lang = getLang(ctx.params[0]); const name = ctx.params[1]; const ep = endpoints.find(e => e.name === name); @@ -194,7 +202,7 @@ router.get('/*/api/endpoints/*', async ctx => { }); router.get('/*/api/entities/*', async ctx => { - const lang = ctx.params[0]; + const lang = getLang(ctx.params[0]); const entity = ctx.params[1]; const x = yaml.safeLoad(fs.readFileSync(path.resolve(`${__dirname}/../../../src/docs/api/entities/${entity}.yaml`), 'utf-8')); @@ -211,7 +219,7 @@ router.get('/*/api/entities/*', async ctx => { }); router.get('/*/*', async ctx => { - const lang = ctx.params[0]; + const lang = getLang(ctx.params[0]); const doc = ctx.params[1]; showdown.extension('urlExtension', () => ({