mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 22:58:07 +02:00
Use the fetchData
helper function in more cases
- Extend the `fetchData` helper function to also support fetching of "blob" data. - Use the `fetchData` helper function more in the code-base, when fetching non-PDF data. Given that the Fetch API isn't supported for all protocols, this should improve compatibility for the PDF.js library.
This commit is contained in:
parent
d679078beb
commit
fd7a7e2859
3 changed files with 19 additions and 16 deletions
|
@ -15,10 +15,10 @@
|
|||
|
||||
/** @typedef {import("./interfaces").IL10n} IL10n */
|
||||
|
||||
import { fetchData, shadow } from "pdfjs-lib";
|
||||
import { FluentBundle, FluentResource } from "fluent-bundle";
|
||||
import { DOMLocalization } from "fluent-dom";
|
||||
import { L10n } from "./l10n.js";
|
||||
import { shadow } from "pdfjs-lib";
|
||||
|
||||
/**
|
||||
* @implements {IL10n}
|
||||
|
@ -32,14 +32,14 @@ class ConstL10n extends L10n {
|
|||
}
|
||||
|
||||
static async *#generateBundles(lang) {
|
||||
let text;
|
||||
if (typeof PDFJSDev === "undefined") {
|
||||
const url = new URL(`./locale/${lang}/viewer.ftl`, window.location.href);
|
||||
const data = await fetch(url);
|
||||
text = await data.text();
|
||||
} else {
|
||||
text = PDFJSDev.eval("DEFAULT_FTL");
|
||||
}
|
||||
const text =
|
||||
typeof PDFJSDev === "undefined"
|
||||
? await fetchData(
|
||||
new URL(`./locale/${lang}/viewer.ftl`, window.location.href),
|
||||
/* type = */ "text"
|
||||
)
|
||||
: PDFJSDev.eval("DEFAULT_FTL");
|
||||
|
||||
const resource = new FluentResource(text);
|
||||
const bundle = new FluentBundle(lang);
|
||||
const errors = bundle.addResource(resource);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue