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