Merge pull request #312 from incubateur-territoires/arnaudpeich/Split_client_and_server_translations_organize_by_filename

Split client and server translations, organize by filename
This commit is contained in:
jarek
2022-10-19 10:38:39 +02:00
committed by GitHub
11 changed files with 86 additions and 60 deletions

View File

@@ -12,6 +12,8 @@ import jsesc from 'jsesc';
import * as handlebars from 'handlebars';
import * as path from 'path';
const translate = (req: express.Request, key: string, args?: any) => req.t(`sendAppPage.${key}`, args);
export interface ISendAppPageOptions {
path: string; // Ignored if .content is present (set to "" for clarity).
content?: string;
@@ -155,7 +157,7 @@ function configuredPageTitleSuffix() {
*/
function getPageTitle(req: express.Request, config: GristLoadConfig): string {
const maybeDoc = getDocFromConfig(config);
if (!maybeDoc) { return req.t('Loading') + "..."; }
if (!maybeDoc) { return translate(req, 'sendAppPage.Loading') + "..."; }
return handlebars.Utils.escapeExpression(maybeDoc.name);
}

View File

@@ -26,8 +26,8 @@ export function setupLocale(appRoot: string): i18n {
supportedNamespaces.add(namespace);
return lang;
}).filter((lang) => lang));
if (!supportedLngs.has('en') || !supportedNamespaces.has('core')) {
throw new Error("Missing core English language file");
if (!supportedLngs.has('en') || !supportedNamespaces.has('server')) {
throw new Error("Missing server English language file");
}
// Initialize localization filesystem plugin that will read the locale files from the localeDir.
instance.use(i18fsBackend);
@@ -40,7 +40,7 @@ export function setupLocale(appRoot: string): i18n {
initImmediate: false,
preload: [...supportedLngs],
supportedLngs: [...supportedLngs],
defaultNS: 'core',
defaultNS: 'server',
ns: [...supportedNamespaces],
fallbackLng: 'en',
backend: {
@@ -71,5 +71,5 @@ export function readLoadedNamespaces(instance?: i18n): readonly string[] {
if (Array.isArray(instance?.options.ns)) {
return instance.options.ns;
}
return instance?.options.ns ? [instance.options.ns as string] : ['core'];
return instance?.options.ns ? [instance.options.ns as string] : ['server'];
}