UNPKG

5.15 kBJavaScriptView Raw
1/**
2 * @licstart The following is the entire license notice for the
3 * JavaScript code in this page
4 *
5 * Copyright 2022 Mozilla Foundation
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * @licend The above is the entire license notice for the
20 * JavaScript code in this page
21 */
22"use strict";
23
24Object.defineProperty(exports, "__esModule", {
25 value: true
26});
27exports.NullL10n = void 0;
28exports.fixupLangCode = fixupLangCode;
29exports.getL10nFallback = getL10nFallback;
30const DEFAULT_L10N_STRINGS = {
31 of_pages: "of {{pagesCount}}",
32 page_of_pages: "({{pageNumber}} of {{pagesCount}})",
33 document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
34 document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
35 document_properties_date_string: "{{date}}, {{time}}",
36 document_properties_page_size_unit_inches: "in",
37 document_properties_page_size_unit_millimeters: "mm",
38 document_properties_page_size_orientation_portrait: "portrait",
39 document_properties_page_size_orientation_landscape: "landscape",
40 document_properties_page_size_name_a3: "A3",
41 document_properties_page_size_name_a4: "A4",
42 document_properties_page_size_name_letter: "Letter",
43 document_properties_page_size_name_legal: "Legal",
44 document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})",
45 document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
46 document_properties_linearized_yes: "Yes",
47 document_properties_linearized_no: "No",
48 print_progress_percent: "{{progress}}%",
49 "toggle_sidebar.title": "Toggle Sidebar",
50 "toggle_sidebar_notification2.title": "Toggle Sidebar (document contains outline/attachments/layers)",
51 additional_layers: "Additional Layers",
52 page_landmark: "Page {{page}}",
53 thumb_page_title: "Page {{page}}",
54 thumb_page_canvas: "Thumbnail of Page {{page}}",
55 find_reached_top: "Reached top of document, continued from bottom",
56 find_reached_bottom: "Reached end of document, continued from top",
57 "find_match_count[one]": "{{current}} of {{total}} match",
58 "find_match_count[other]": "{{current}} of {{total}} matches",
59 "find_match_count_limit[one]": "More than {{limit}} match",
60 "find_match_count_limit[other]": "More than {{limit}} matches",
61 find_not_found: "Phrase not found",
62 error_version_info: "PDF.js v{{version}} (build: {{build}})",
63 error_message: "Message: {{message}}",
64 error_stack: "Stack: {{stack}}",
65 error_file: "File: {{file}}",
66 error_line: "Line: {{line}}",
67 rendering_error: "An error occurred while rendering the page.",
68 page_scale_width: "Page Width",
69 page_scale_fit: "Page Fit",
70 page_scale_auto: "Automatic Zoom",
71 page_scale_actual: "Actual Size",
72 page_scale_percent: "{{scale}}%",
73 loading: "Loading…",
74 loading_error: "An error occurred while loading the PDF.",
75 invalid_file_error: "Invalid or corrupted PDF file.",
76 missing_file_error: "Missing PDF file.",
77 unexpected_response_error: "Unexpected server response.",
78 printing_not_supported: "Warning: Printing is not fully supported by this browser.",
79 printing_not_ready: "Warning: The PDF is not fully loaded for printing.",
80 web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts.",
81 free_text_default_content: "Enter text…",
82 editor_free_text_aria_label: "FreeText Editor",
83 editor_ink_aria_label: "Ink Editor",
84 editor_ink_canvas_aria_label: "User-created image"
85};
86
87function getL10nFallback(key, args) {
88 switch (key) {
89 case "find_match_count":
90 key = `find_match_count[${args.total === 1 ? "one" : "other"}]`;
91 break;
92
93 case "find_match_count_limit":
94 key = `find_match_count_limit[${args.limit === 1 ? "one" : "other"}]`;
95 break;
96 }
97
98 return DEFAULT_L10N_STRINGS[key] || "";
99}
100
101const PARTIAL_LANG_CODES = {
102 en: "en-US",
103 es: "es-ES",
104 fy: "fy-NL",
105 ga: "ga-IE",
106 gu: "gu-IN",
107 hi: "hi-IN",
108 hy: "hy-AM",
109 nb: "nb-NO",
110 ne: "ne-NP",
111 nn: "nn-NO",
112 pa: "pa-IN",
113 pt: "pt-PT",
114 sv: "sv-SE",
115 zh: "zh-CN"
116};
117
118function fixupLangCode(langCode) {
119 return PARTIAL_LANG_CODES[langCode?.toLowerCase()] || langCode;
120}
121
122function formatL10nValue(text, args) {
123 if (!args) {
124 return text;
125 }
126
127 return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
128 return name in args ? args[name] : "{{" + name + "}}";
129 });
130}
131
132const NullL10n = {
133 async getLanguage() {
134 return "en-us";
135 },
136
137 async getDirection() {
138 return "ltr";
139 },
140
141 async get(key, args = null, fallback = getL10nFallback(key, args)) {
142 return formatL10nValue(fallback, args);
143 },
144
145 async translate(element) {}
146
147};
148exports.NullL10n = NullL10n;
\No newline at end of file