1
0
Fork 0
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:
Jonas Jenwald 2023-11-14 16:09:05 +01:00 committed by GitHub
commit 1df648733e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 20 deletions

View file

@ -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 };
}
}

View file

@ -35,6 +35,7 @@ const {
createValidAbsoluteUrl,
DOMSVGFactory,
FeatureTest,
fetchData,
getDocument,
getFilenameFromUrl,
getPdfFilenameFromUrl,
@ -80,6 +81,7 @@ export {
createValidAbsoluteUrl,
DOMSVGFactory,
FeatureTest,
fetchData,
getDocument,
getFilenameFromUrl,
getPdfFilenameFromUrl,