mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 22:58:07 +02:00
Re-factor how the GenericL10n
class fetches localization-data
- Re-factor the existing `fetchData` helper function such that it can fetch more types of data, and it now supports "arraybuffer", "json", and "text". This only needed minor adjustments in the `DOMCMapReaderFactory` and `DOMStandardFontDataFactory` classes.[1] - Expose the `fetchData` helper function in the API, such that the viewer is able to access it. - Use the `fetchData` helper function in the `GenericL10n` class, since this should allow fetching of localization-data even if the default viewer is run in an environment without support for the Fetch API. --- [1] While testing this I also noticed a minor inconsistency when handling standard font-data on the worker-thread.
This commit is contained in:
parent
44cde3ccca
commit
709d89420e
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