l10n_utils.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. Object.defineProperty(exports, "__esModule", {
  24. value: true
  25. });
  26. exports.NullL10n = void 0;
  27. exports.fixupLangCode = fixupLangCode;
  28. exports.getL10nFallback = getL10nFallback;
  29. const DEFAULT_L10N_STRINGS = {
  30. of_pages: "of {{pagesCount}}",
  31. page_of_pages: "({{pageNumber}} of {{pagesCount}})",
  32. document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
  33. document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
  34. document_properties_date_string: "{{date}}, {{time}}",
  35. document_properties_page_size_unit_inches: "in",
  36. document_properties_page_size_unit_millimeters: "mm",
  37. document_properties_page_size_orientation_portrait: "portrait",
  38. document_properties_page_size_orientation_landscape: "landscape",
  39. document_properties_page_size_name_a3: "A3",
  40. document_properties_page_size_name_a4: "A4",
  41. document_properties_page_size_name_letter: "Letter",
  42. document_properties_page_size_name_legal: "Legal",
  43. document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})",
  44. document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
  45. document_properties_linearized_yes: "Yes",
  46. document_properties_linearized_no: "No",
  47. print_progress_percent: "{{progress}}%",
  48. "toggle_sidebar.title": "Toggle Sidebar",
  49. "toggle_sidebar_notification2.title": "Toggle Sidebar (document contains outline/attachments/layers)",
  50. additional_layers: "Additional Layers",
  51. page_landmark: "Page {{page}}",
  52. thumb_page_title: "Page {{page}}",
  53. thumb_page_canvas: "Thumbnail of Page {{page}}",
  54. find_reached_top: "Reached top of document, continued from bottom",
  55. find_reached_bottom: "Reached end of document, continued from top",
  56. "find_match_count[one]": "{{current}} of {{total}} match",
  57. "find_match_count[other]": "{{current}} of {{total}} matches",
  58. "find_match_count_limit[one]": "More than {{limit}} match",
  59. "find_match_count_limit[other]": "More than {{limit}} matches",
  60. find_not_found: "Phrase not found",
  61. error_version_info: "PDF.js v{{version}} (build: {{build}})",
  62. error_message: "Message: {{message}}",
  63. error_stack: "Stack: {{stack}}",
  64. error_file: "File: {{file}}",
  65. error_line: "Line: {{line}}",
  66. rendering_error: "An error occurred while rendering the page.",
  67. page_scale_width: "Page Width",
  68. page_scale_fit: "Page Fit",
  69. page_scale_auto: "Automatic Zoom",
  70. page_scale_actual: "Actual Size",
  71. page_scale_percent: "{{scale}}%",
  72. loading: "Loading…",
  73. loading_error: "An error occurred while loading the PDF.",
  74. invalid_file_error: "Invalid or corrupted PDF file.",
  75. missing_file_error: "Missing PDF file.",
  76. unexpected_response_error: "Unexpected server response.",
  77. printing_not_supported: "Warning: Printing is not fully supported by this browser.",
  78. printing_not_ready: "Warning: The PDF is not fully loaded for printing.",
  79. web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts.",
  80. free_text_default_content: "Enter text…",
  81. editor_free_text_aria_label: "FreeText Editor",
  82. editor_ink_aria_label: "Ink Editor",
  83. editor_ink_canvas_aria_label: "User-created image"
  84. };
  85. function getL10nFallback(key, args) {
  86. switch (key) {
  87. case "find_match_count":
  88. key = `find_match_count[${args.total === 1 ? "one" : "other"}]`;
  89. break;
  90. case "find_match_count_limit":
  91. key = `find_match_count_limit[${args.limit === 1 ? "one" : "other"}]`;
  92. break;
  93. }
  94. return DEFAULT_L10N_STRINGS[key] || "";
  95. }
  96. const PARTIAL_LANG_CODES = {
  97. en: "en-US",
  98. es: "es-ES",
  99. fy: "fy-NL",
  100. ga: "ga-IE",
  101. gu: "gu-IN",
  102. hi: "hi-IN",
  103. hy: "hy-AM",
  104. nb: "nb-NO",
  105. ne: "ne-NP",
  106. nn: "nn-NO",
  107. pa: "pa-IN",
  108. pt: "pt-PT",
  109. sv: "sv-SE",
  110. zh: "zh-CN"
  111. };
  112. function fixupLangCode(langCode) {
  113. return PARTIAL_LANG_CODES[langCode?.toLowerCase()] || langCode;
  114. }
  115. function formatL10nValue(text, args) {
  116. if (!args) {
  117. return text;
  118. }
  119. return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
  120. return name in args ? args[name] : "{{" + name + "}}";
  121. });
  122. }
  123. const NullL10n = {
  124. async getLanguage() {
  125. return "en-us";
  126. },
  127. async getDirection() {
  128. return "ltr";
  129. },
  130. async get(key, args = null, fallback = getL10nFallback(key, args)) {
  131. return formatL10nValue(fallback, args);
  132. },
  133. async translate(element) {}
  134. };
  135. exports.NullL10n = NullL10n;