mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 14:48:08 +02:00
[api-minor] Re-factor NullL10n
and remove the hard-coded l10n strings (PR 17115 follow-up)
*Please note:* These changes only affect the GENERIC build, since `NullL10n` is only a stub elsewhere (see PR 17135). After the changes in PR 17115, which modernized and improved l10n-handling, the `NullL10n`-implementation is no longer a good fallback for the "proper" `L10n`-classes. To improve this situation, especially for the *standalone* viewer-components, this patch makes the following changes: - Let the `NullL10n`-implementation extend an actual `L10n`-class, which is constant and lazily initialized, to ensure that it works *exactly* like the "proper" ones. - Automatically bundle the "en-US" l10n-strings in the build, via the pre-processor, such that we don't need to remember to manually update them. - Ensure that the *standalone* viewer-components register their DOM-elements for translation, similar to the default viewer, since this will allow future code improvements by using "data-l10n-id"/"data-l10n-args" in most (if not all) parts of the viewer. - Remove the `NullL10n` from the `AnnotationLayer`, to avoid affecting bundle size too much. For third-party users that access the `AnnotationLayer`, as exposed in the main PDF.js library, they'll now need to *manually* register it for translation. (However, the *standalone* viewer-components still works given the point above.)
This commit is contained in:
parent
a4cd2ef1db
commit
f07675a6a8
11 changed files with 72 additions and 125 deletions
20
gulpfile.mjs
20
gulpfile.mjs
|
@ -192,6 +192,7 @@ function createWebpackConfig(
|
|||
DEFAULT_PREFERENCES: defaultPreferencesDir
|
||||
? getDefaultPreferences(defaultPreferencesDir)
|
||||
: {},
|
||||
DEFAULT_FTL: defines.GENERIC ? getDefaultFtl() : "",
|
||||
};
|
||||
const licenseHeaderLibre = fs
|
||||
.readFileSync("./src/license_header_libre.js")
|
||||
|
@ -246,7 +247,6 @@ function createWebpackConfig(
|
|||
};
|
||||
const libraryAlias = {
|
||||
"display-fetch_stream": "src/display/stubs.js",
|
||||
"display-l10n_utils": "src/display/stubs.js",
|
||||
"display-network": "src/display/stubs.js",
|
||||
"display-node_stream": "src/display/stubs.js",
|
||||
"display-node_utils": "src/display/stubs.js",
|
||||
|
@ -280,7 +280,6 @@ function createWebpackConfig(
|
|||
// the tsconfig.json file for the type generation to work.
|
||||
// In the tsconfig.json files, the .js extension must be omitted.
|
||||
libraryAlias["display-fetch_stream"] = "src/display/fetch_stream.js";
|
||||
libraryAlias["display-l10n_utils"] = "web/l10n_utils.js";
|
||||
libraryAlias["display-network"] = "src/display/network.js";
|
||||
libraryAlias["display-node_stream"] = "src/display/node_stream.js";
|
||||
libraryAlias["display-node_utils"] = "src/display/node_utils.js";
|
||||
|
@ -831,6 +830,21 @@ function getDefaultPreferences(dir) {
|
|||
return JSON.parse(str);
|
||||
}
|
||||
|
||||
function getDefaultFtl() {
|
||||
const content = fs.readFileSync("l10n/en-US/viewer.ftl").toString(),
|
||||
stringBuf = [];
|
||||
|
||||
// Strip out comments and line-breaks.
|
||||
const regExp = /^\s*#/;
|
||||
for (const line of content.split("\n")) {
|
||||
if (!line || regExp.test(line)) {
|
||||
continue;
|
||||
}
|
||||
stringBuf.push(line);
|
||||
}
|
||||
return stringBuf.join("\n");
|
||||
}
|
||||
|
||||
gulp.task("locale", function () {
|
||||
const VIEWER_LOCALE_OUTPUT = "web/locale/";
|
||||
|
||||
|
@ -1544,7 +1558,6 @@ function buildLibHelper(bundleDefines, inputStream, outputDir) {
|
|||
map: {
|
||||
"pdfjs-lib": "../pdf.js",
|
||||
"display-fetch_stream": "./fetch_stream.js",
|
||||
"display-l10n_utils": "../web/l10n_utils.js",
|
||||
"display-network": "./network.js",
|
||||
"display-node_stream": "./node_stream.js",
|
||||
"display-node_utils": "./node_utils.js",
|
||||
|
@ -1572,6 +1585,7 @@ function buildLib(defines, dir) {
|
|||
DEFAULT_PREFERENCES: getDefaultPreferences(
|
||||
defines.SKIP_BABEL ? "lib/" : "lib-legacy/"
|
||||
),
|
||||
DEFAULT_FTL: getDefaultFtl(),
|
||||
};
|
||||
|
||||
const inputStream = merge([
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue