mirror of
https://github.com/immich-app/immich.git
synced 2025-12-21 09:15:44 +03:00
fix(web): FormatMessage development keys (#10536)
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
<script lang="ts">
|
||||
import { IntlMessageFormat, type FormatXMLElementFn, type PrimitiveType } from 'intl-messageformat';
|
||||
import { TYPE, type MessageFormatElement } from '@formatjs/icu-messageformat-parser';
|
||||
import { locale as i18nLocale } from 'svelte-i18n';
|
||||
import { locale as i18nLocale, json } from 'svelte-i18n';
|
||||
|
||||
type InterpolationValues = Record<string, PrimitiveType | FormatXMLElementFn<unknown>>;
|
||||
|
||||
export let message: unknown;
|
||||
export let key: string;
|
||||
export let values: InterpolationValues = {};
|
||||
|
||||
const getLocale = (locale?: string | null) => {
|
||||
@@ -16,13 +16,13 @@
|
||||
return locale;
|
||||
};
|
||||
|
||||
const getElements = (message: unknown, locale: string): MessageFormatElement[] => {
|
||||
const getElements = (message: string, locale: string): MessageFormatElement[] => {
|
||||
return new IntlMessageFormat(message as string, locale, undefined, {
|
||||
ignoreTag: false,
|
||||
}).getAst();
|
||||
};
|
||||
|
||||
const getParts = (message: unknown, locale: string) => {
|
||||
const getParts = (message: string, locale: string) => {
|
||||
try {
|
||||
const elements = getElements(message, locale);
|
||||
|
||||
@@ -38,12 +38,13 @@
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
console.warn(`Message "${message}" has syntax error:`, error.message);
|
||||
console.warn(`Message "${key}" has syntax error:`, error.message);
|
||||
}
|
||||
return [{ message: message as string, tag: undefined }];
|
||||
}
|
||||
};
|
||||
|
||||
$: message = ($json(key) as string) || key;
|
||||
$: locale = getLocale($i18nLocale);
|
||||
$: parts = getParts(message, locale);
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user