Fix locale dynamic imports
This commit is contained in:
parent
09ca18891f
commit
97c1dbbd79
5 changed files with 19 additions and 15 deletions
|
@ -4,7 +4,7 @@ import { createSelector } from 'reselect';
|
|||
import { v4 as uuid } from 'uuid';
|
||||
|
||||
import { patchMe } from 'soapbox/actions/me';
|
||||
import messages from 'soapbox/locales/messages';
|
||||
import messages from 'soapbox/messages';
|
||||
import toast from 'soapbox/toast';
|
||||
import { isLoggedIn } from 'soapbox/utils/auth';
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import { getLocale, getSettings } from 'soapbox/actions/settings';
|
|||
import { importEntities } from 'soapbox/entity-store/actions';
|
||||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { selectEntity } from 'soapbox/entity-store/selectors';
|
||||
import messages from 'soapbox/locales/messages';
|
||||
import messages from 'soapbox/messages';
|
||||
import { ChatKeys, IChat, isLastMessage } from 'soapbox/queries/chats';
|
||||
import { queryClient } from 'soapbox/queries/client';
|
||||
import { getUnreadChatsCount, updateChatListItem, updateChatMessage } from 'soapbox/utils/chats';
|
||||
|
|
|
@ -42,7 +42,7 @@ import {
|
|||
useInstance,
|
||||
useRegistrationStatus,
|
||||
} from 'soapbox/hooks';
|
||||
import MESSAGES from 'soapbox/locales/messages';
|
||||
import MESSAGES from 'soapbox/messages';
|
||||
import { normalizeSoapboxConfig } from 'soapbox/normalizers';
|
||||
import { queryClient } from 'soapbox/queries/client';
|
||||
import { useCachedLocationHandler } from 'soapbox/utils/redirect';
|
||||
|
|
|
@ -2,28 +2,32 @@ type MessageJson = Record<string, string>;
|
|||
type MessageModule = { default: MessageJson };
|
||||
|
||||
/** Import custom messages */
|
||||
const importCustom = (locale: string): Promise<MessageModule> => {
|
||||
return import(/* webpackChunkName: "locale_[request]" */`custom/locales/${locale}.json`)
|
||||
.catch(() => ({ default: {} }));
|
||||
const importCustom = async (locale: string): Promise<MessageModule> => {
|
||||
try {
|
||||
return await import(`../../custom/locales/${locale}.json`);
|
||||
} catch {
|
||||
return ({ default: {} });
|
||||
}
|
||||
};
|
||||
|
||||
/** Import git-checked messages */
|
||||
const importMessages = (locale: string): Promise<MessageModule> => {
|
||||
return import(/* webpackChunkName: "locale_[request]" */`./${locale}.json`);
|
||||
return import(`./locales/${locale}.json`);
|
||||
};
|
||||
|
||||
/** Override custom messages */
|
||||
const importMessagesWithCustom = (locale: string): Promise<MessageJson> => {
|
||||
return Promise.all([
|
||||
importMessages(locale),
|
||||
importCustom(locale),
|
||||
]).then(messages => {
|
||||
const importMessagesWithCustom = async (locale: string): Promise<MessageJson> => {
|
||||
try {
|
||||
const messages = await Promise.all([
|
||||
importMessages(locale),
|
||||
importCustom(locale),
|
||||
]);
|
||||
const [native, custom] = messages;
|
||||
return Object.assign(native.default, custom.default);
|
||||
}).catch(error => {
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const locales = [
|
|
@ -1,6 +1,6 @@
|
|||
import { z } from 'zod';
|
||||
|
||||
import { locales } from 'soapbox/locales/messages';
|
||||
import { locales } from 'soapbox/messages';
|
||||
|
||||
const skinToneSchema = z.union([
|
||||
z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5), z.literal(6),
|
||||
|
|
Loading…
Reference in a new issue