[GENERIC viewer] Add Fluent PLATFORM function (PR 19414 follow-up)
This patch extends the `FeatureTest.platform` getter to provide the necessary information, and uses that one to implement a Fluent `PLATFORM` function based on: https://searchfox.org/mozilla-central/rev/d1fbe983fb7720f0a4aca0e748817af11c1a374e/intl/l10n/rust/fluent-ffi/src/bundle.rs#81-98
This commit is contained in:
parent
f1152f5caf
commit
d5d3d8b3f7
@ -632,18 +632,24 @@ class FeatureTest {
|
|||||||
if (
|
if (
|
||||||
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
|
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
|
||||||
(typeof navigator !== "undefined" &&
|
(typeof navigator !== "undefined" &&
|
||||||
typeof navigator?.platform === "string")
|
typeof navigator?.platform === "string" &&
|
||||||
|
typeof navigator?.userAgent === "string")
|
||||||
) {
|
) {
|
||||||
|
const { platform, userAgent } = navigator;
|
||||||
|
|
||||||
return shadow(this, "platform", {
|
return shadow(this, "platform", {
|
||||||
isMac: navigator.platform.includes("Mac"),
|
isAndroid: userAgent.includes("Android"),
|
||||||
isWindows: navigator.platform.includes("Win"),
|
isLinux: platform.includes("Linux"),
|
||||||
|
isMac: platform.includes("Mac"),
|
||||||
|
isWindows: platform.includes("Win"),
|
||||||
isFirefox:
|
isFirefox:
|
||||||
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
|
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
|
||||||
(typeof navigator?.userAgent === "string" &&
|
userAgent.includes("Firefox"),
|
||||||
navigator.userAgent.includes("Firefox")),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return shadow(this, "platform", {
|
return shadow(this, "platform", {
|
||||||
|
isAndroid: false,
|
||||||
|
isLinux: false,
|
||||||
isMac: false,
|
isMac: false,
|
||||||
isWindows: false,
|
isWindows: false,
|
||||||
isFirefox: false,
|
isFirefox: false,
|
||||||
|
|||||||
@ -15,14 +15,33 @@
|
|||||||
|
|
||||||
/** @typedef {import("./interfaces").IL10n} IL10n */
|
/** @typedef {import("./interfaces").IL10n} IL10n */
|
||||||
|
|
||||||
|
import { FeatureTest, fetchData } from "pdfjs-lib";
|
||||||
import { FluentBundle, FluentResource } from "fluent-bundle";
|
import { FluentBundle, FluentResource } from "fluent-bundle";
|
||||||
import { DOMLocalization } from "fluent-dom";
|
import { DOMLocalization } from "fluent-dom";
|
||||||
import { fetchData } from "pdfjs-lib";
|
|
||||||
import { L10n } from "./l10n.js";
|
import { L10n } from "./l10n.js";
|
||||||
|
|
||||||
|
function PLATFORM() {
|
||||||
|
const { isAndroid, isLinux, isMac, isWindows } = FeatureTest.platform;
|
||||||
|
if (isLinux) {
|
||||||
|
return "linux";
|
||||||
|
}
|
||||||
|
if (isWindows) {
|
||||||
|
return "windows";
|
||||||
|
}
|
||||||
|
if (isMac) {
|
||||||
|
return "macos";
|
||||||
|
}
|
||||||
|
if (isAndroid) {
|
||||||
|
return "android";
|
||||||
|
}
|
||||||
|
return "other";
|
||||||
|
}
|
||||||
|
|
||||||
function createBundle(lang, text) {
|
function createBundle(lang, text) {
|
||||||
const resource = new FluentResource(text);
|
const resource = new FluentResource(text);
|
||||||
const bundle = new FluentBundle(lang);
|
const bundle = new FluentBundle(lang, {
|
||||||
|
functions: { PLATFORM },
|
||||||
|
});
|
||||||
const errors = bundle.addResource(resource);
|
const errors = bundle.addResource(resource);
|
||||||
if (errors.length) {
|
if (errors.length) {
|
||||||
console.error("L10n errors", errors);
|
console.error("L10n errors", errors);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user