Split client and server translations, organize by filename

This commit is contained in:
Arnaud Peich
2022-10-13 11:23:55 +02:00
parent 396153b1eb
commit cc2a438fe5
10 changed files with 72 additions and 53 deletions

View File

@@ -15,7 +15,7 @@ export async function setupLocale() {
}
}
const ns = getGristConfig().namespaces ?? ['core'];
const ns = getGristConfig().namespaces ?? ['client'];
// Initialize localization plugin
try {
// We don't await this promise, as it is resolved synchronously due to initImmediate: false.
@@ -28,13 +28,13 @@ export async function setupLocale() {
initImmediate: false,
// Read language from navigator object.
lng,
// By default we use core namespace.
defaultNS: 'core',
// By default we use client namespace.
defaultNS: 'client',
// Read namespaces that are supported by the server.
// TODO: this can be converted to a dynamic list of namespaces, for async components.
// for now just import all what server offers.
// We can fallback to core namespace for any addons.
fallbackNS: 'core',
// We can fallback to client namespace for any addons.
fallbackNS: 'client',
ns,
supportedLngs
}).catch((err: any) => {

View File

@@ -8,7 +8,7 @@ export function addNewButton(isOpen: Observable<boolean> | boolean = true, ...ar
cssAddNewButton.cls('-open', isOpen),
// Setting spacing as flex items allows them to shrink faster when there isn't enough space.
cssLeftMargin(),
cssAddText(t('AddNew')),
cssAddText(t('AddNewButton.AddNew')),
dom('div', {style: 'flex: 1 1 16px'}),
cssPlusButton(cssPlusIcon('Plus')),
dom('div', {style: 'flex: 0 1 16px'}),

View File

@@ -105,10 +105,10 @@ function createLoadedDocMenu(owner: IDisposableOwner, home: HomeModel) {
null :
css.docListHeader(
(
page === 'all' ? t('AllDocuments') :
page === 'all' ? t('DocMenu.AllDocuments') :
page === 'templates' ?
dom.domComputed(use => use(home.featuredTemplates).length > 0, (hasFeaturedTemplates) =>
hasFeaturedTemplates ? t('MoreExamplesAndTemplates') : t('ExamplesAndTemplates')
hasFeaturedTemplates ? t('DocMenu.MoreExamplesAndTemplates') : t('DocMenu.ExamplesAndTemplates')
) :
page === 'trash' ? 'Trash' :
workspace && [css.docHeaderIcon('Folder'), workspaceName(home.app, workspace)]
@@ -268,7 +268,7 @@ function buildOtherSites(home: HomeModel) {
return css.otherSitesBlock(
dom.autoDispose(hideOtherSitesObs),
css.otherSitesHeader(
t('OtherSites'),
t('DocMenu.OtherSites'),
dom.domComputed(hideOtherSitesObs, (collapsed) =>
collapsed ? css.otherSitesHeaderIcon('Expand') : css.otherSitesHeaderIcon('Collapse')
),
@@ -280,7 +280,7 @@ function buildOtherSites(home: HomeModel) {
const siteName = home.app.currentOrgName;
return [
dom('div',
t('OtherSitesWelcome', { siteName, context: personal ? 'personal' : '' }),
t('DocMenu.OtherSitesWelcome', { siteName, context: personal ? 'personal' : '' }),
testId('other-sites-message')
),
css.otherSitesButtons(

View File

@@ -110,9 +110,9 @@ function makePersonalIntro(homeModel: HomeModel, user: FullUser) {
}
function makeAnonIntro(homeModel: HomeModel) {
const signUp = cssLink({href: getLoginOrSignupUrl()}, t('SignUp'));
const signUp = cssLink({href: getLoginOrSignupUrl()}, t('HomeIntro.SignUp'));
return [
css.docListHeader(t('Welcome'), testId('welcome-title')),
css.docListHeader(t('HomeIntro.Welcome'), testId('welcome-title')),
cssIntroLine('Get started by exploring templates, or creating your first Grist document.'),
cssIntroLine(signUp, ' to save your work.',
(shouldHideUiElement('helpCenter') ? null : [' Visit our ', helpCenterLink(), ' to learn more.']),

View File

@@ -154,7 +154,7 @@ function configuredPageTitleSuffix() {
*/
function getPageTitle(req: express.Request, config: GristLoadConfig): string {
const maybeDoc = getDocFromConfig(config);
if (!maybeDoc) { return req.t('Loading') + "..."; }
if (!maybeDoc) { return req.t('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'];
}