1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 14:48:08 +02:00

[api-minor] Move to Fluent for the localization (bug 1858715)

- For the generic viewer we use @fluent/dom and @fluent/bundle
- For the builtin pdf viewer in Firefox, we set a localization url
  and then we rely on document.l10n which is a DOMLocalization object.
This commit is contained in:
Calixte Denizet 2023-10-13 16:23:17 +02:00
parent 2a3090224f
commit 66982a2a11
155 changed files with 1311 additions and 28684 deletions

View file

@ -240,6 +240,8 @@ function createWebpackConfig(
pdfjs: "src",
"pdfjs-web": "web",
"pdfjs-lib": "web/pdfjs",
"fluent-bundle": "node_modules/@fluent/bundle/esm/index.js",
"fluent-dom": "node_modules/@fluent/dom/esm/index.js",
};
const libraryAlias = {
"display-fetch_stream": "src/display/stubs.js",
@ -836,7 +838,7 @@ gulp.task("locale", function () {
const subfolders = fs.readdirSync(L10N_DIR);
subfolders.sort();
let viewerOutput = "";
const viewerOutput = Object.create(null);
const locales = [];
for (const locale of subfolders) {
const dirPath = L10N_DIR + locale;
@ -852,23 +854,19 @@ gulp.task("locale", function () {
locales.push(locale);
if (checkFile(dirPath + "/viewer.properties")) {
viewerOutput +=
"[" +
locale +
"]\n" +
"@import url(" +
locale +
"/viewer.properties)\n\n";
if (checkFile(dirPath + "/viewer.ftl")) {
viewerOutput[locale] = `${locale}/viewer.ftl`;
}
}
const glob = locales.length === 1 ? locales[0] : `{${locales.join(",")}}`;
return merge([
createStringSource("locale.properties", viewerOutput).pipe(
createStringSource("locale.json", JSON.stringify(viewerOutput)).pipe(
gulp.dest(VIEWER_LOCALE_OUTPUT)
),
gulp
.src(L10N_DIR + "/{" + locales.join(",") + "}/viewer.properties", {
.src(`${L10N_DIR}/${glob}/viewer.ftl`, {
base: L10N_DIR,
})
.pipe(gulp.dest(VIEWER_LOCALE_OUTPUT)),
@ -950,7 +948,7 @@ function buildGeneric(defines, dir) {
gulp.src(COMMON_WEB_FILES, { base: "web/" }).pipe(gulp.dest(dir + "web")),
gulp.src("LICENSE").pipe(gulp.dest(dir)),
gulp
.src(["web/locale/*/viewer.properties", "web/locale/locale.properties"], {
.src(["web/locale/*/viewer.ftl", "web/locale/locale.json"], {
base: "web/",
})
.pipe(gulp.dest(dir + "web")),
@ -1376,9 +1374,7 @@ gulp.task(
.pipe(replaceMozcentralCSS())
.pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR + "web")),
gulp
.src("l10n/en-US/*.properties")
.pipe(gulp.dest(MOZCENTRAL_L10N_DIR)),
gulp.src("l10n/en-US/*.ftl").pipe(gulp.dest(MOZCENTRAL_L10N_DIR)),
gulp.src("LICENSE").pipe(gulp.dest(MOZCENTRAL_EXTENSION_DIR)),
gulp
.src(FIREFOX_CONTENT_DIR + "PdfJsDefaultPreferences.sys.mjs")
@ -1446,10 +1442,9 @@ gulp.task(
.pipe(gulp.dest(CHROME_BUILD_CONTENT_DIR + "web")),
gulp
.src(
["web/locale/*/viewer.properties", "web/locale/locale.properties"],
{ base: "web/" }
)
.src(["web/locale/*/viewer.ftl", "web/locale/locale.json"], {
base: "web/",
})
.pipe(gulp.dest(CHROME_BUILD_CONTENT_DIR + "web")),
createCMapBundle().pipe(
gulp.dest(CHROME_BUILD_CONTENT_DIR + "web/cmaps")
@ -1559,6 +1554,8 @@ function buildLibHelper(bundleDefines, inputStream, outputDir) {
"display-network": "./network.js",
"display-node_stream": "./node_stream.js",
"display-node_utils": "./node_utils.js",
"fluent-bundle": "../../../node_modules/@fluent/bundle/esm/index.js",
"fluent-dom": "../../../node_modules/@fluent/dom/esm/index.js",
},
};
const licenseHeaderLibre = fs
@ -1589,10 +1586,7 @@ function buildLib(defines, dir) {
],
{ base: "src/" }
),
gulp.src(
["external/webL10n/l10n.js", "web/*.js", "!web/{pdfjs,viewer}.js"],
{ base: "." }
),
gulp.src(["web/*.js", "!web/{pdfjs,viewer}.js"], { base: "." }),
gulp.src("test/unit/*.js", { base: "." }),
]);