mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 22:58:07 +02:00
Merge pull request #17277 from Snuffleupagus/L10n-fetchData
Re-factor how the `GenericL10n` class fetches localization-data
This commit is contained in:
commit
1df648733e
6 changed files with 45 additions and 20 deletions
|
@ -17,6 +17,7 @@
|
|||
|
||||
import { FluentBundle, FluentResource } from "fluent-bundle";
|
||||
import { DOMLocalization } from "fluent-dom";
|
||||
import { fetchData } from "pdfjs-lib";
|
||||
import { L10n } from "./l10n.js";
|
||||
|
||||
/**
|
||||
|
@ -71,8 +72,8 @@ class GenericL10n extends L10n {
|
|||
return null;
|
||||
}
|
||||
const url = new URL(path, baseURL);
|
||||
const data = await fetch(url);
|
||||
const text = await data.text();
|
||||
const text = await fetchData(url, /* type = */ "text");
|
||||
|
||||
const resource = new FluentResource(text);
|
||||
const bundle = new FluentBundle(lang);
|
||||
const errors = bundle.addResource(resource);
|
||||
|
@ -84,8 +85,8 @@ class GenericL10n extends L10n {
|
|||
|
||||
static async #getPaths() {
|
||||
const { href } = document.querySelector(`link[type="application/l10n"]`);
|
||||
const data = await fetch(href);
|
||||
const paths = await data.json();
|
||||
const paths = await fetchData(href, /* type = */ "json");
|
||||
|
||||
return { baseURL: href.replace(/[^/]*$/, "") || "./", paths };
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ const {
|
|||
createValidAbsoluteUrl,
|
||||
DOMSVGFactory,
|
||||
FeatureTest,
|
||||
fetchData,
|
||||
getDocument,
|
||||
getFilenameFromUrl,
|
||||
getPdfFilenameFromUrl,
|
||||
|
@ -80,6 +81,7 @@ export {
|
|||
createValidAbsoluteUrl,
|
||||
DOMSVGFactory,
|
||||
FeatureTest,
|
||||
fetchData,
|
||||
getDocument,
|
||||
getFilenameFromUrl,
|
||||
getPdfFilenameFromUrl,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue