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