mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-31 13:07:49 +00:00
Split cached translation fragments
This commit is contained in:
parent
9e35c1ab68
commit
aa25d9a2ff
@ -23,6 +23,10 @@ export async function getTranslation(
|
|||||||
language: string,
|
language: string,
|
||||||
base_url?: string
|
base_url?: string
|
||||||
) {
|
) {
|
||||||
|
const translationsBase = base_url || "core";
|
||||||
|
if (!translations[translationsBase]) {
|
||||||
|
translations[translationsBase] = {};
|
||||||
|
}
|
||||||
const metadata = translationMetadata.translations[language];
|
const metadata = translationMetadata.translations[language];
|
||||||
if (!metadata) {
|
if (!metadata) {
|
||||||
if (language !== "en") {
|
if (language !== "en") {
|
||||||
@ -37,14 +41,14 @@ export async function getTranslation(
|
|||||||
}.json`;
|
}.json`;
|
||||||
|
|
||||||
// Fetch translation from the server
|
// Fetch translation from the server
|
||||||
if (!translations[fingerprint]) {
|
if (!translations[translationsBase][fingerprint]) {
|
||||||
translations[fingerprint] = fetchTranslation(
|
translations[translationsBase][fingerprint] = fetchTranslation(
|
||||||
fingerprint,
|
fingerprint,
|
||||||
base_url || DEFAULT_BASE_URL
|
base_url || DEFAULT_BASE_URL
|
||||||
)
|
)
|
||||||
.then((data) => ({ language, data }))
|
.then((data) => ({ language, data }))
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
delete translations[fingerprint];
|
delete translations[translationsBase][fingerprint];
|
||||||
if (language !== "en") {
|
if (language !== "en") {
|
||||||
// Couldn't load selected translation. Try a fall back to en before failing.
|
// Couldn't load selected translation. Try a fall back to en before failing.
|
||||||
return getTranslation(fragment, "en", base_url);
|
return getTranslation(fragment, "en", base_url);
|
||||||
@ -52,5 +56,5 @@ export async function getTranslation(
|
|||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return translations[fingerprint];
|
return translations[translationsBase][fingerprint];
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user