l10n_utils.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2021 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.getL10nFallback = getL10nFallback;
  27. exports.NullL10n = void 0;
  28. const DEFAULT_L10N_STRINGS = {
  29. of_pages: "of {{pagesCount}}",
  30. page_of_pages: "({{pageNumber}} of {{pagesCount}})",
  31. document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
  32. document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
  33. document_properties_date_string: "{{date}}, {{time}}",
  34. document_properties_page_size_unit_inches: "in",
  35. document_properties_page_size_unit_millimeters: "mm",
  36. document_properties_page_size_orientation_portrait: "portrait",
  37. document_properties_page_size_orientation_landscape: "landscape",
  38. document_properties_page_size_name_a3: "A3",
  39. document_properties_page_size_name_a4: "A4",
  40. document_properties_page_size_name_letter: "Letter",
  41. document_properties_page_size_name_legal: "Legal",
  42. document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})",
  43. document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
  44. document_properties_linearized_yes: "Yes",
  45. document_properties_linearized_no: "No",
  46. print_progress_percent: "{{progress}}%",
  47. "toggle_sidebar.title": "Toggle Sidebar",
  48. "toggle_sidebar_notification2.title": "Toggle Sidebar (document contains outline/attachments/layers)",
  49. additional_layers: "Additional Layers",
  50. page_landmark: "Page {{page}}",
  51. thumb_page_title: "Page {{page}}",
  52. thumb_page_canvas: "Thumbnail of Page {{page}}",
  53. find_reached_top: "Reached top of document, continued from bottom",
  54. find_reached_bottom: "Reached end of document, continued from top",
  55. "find_match_count[one]": "{{current}} of {{total}} match",
  56. "find_match_count[other]": "{{current}} of {{total}} matches",
  57. "find_match_count_limit[one]": "More than {{limit}} match",
  58. "find_match_count_limit[other]": "More than {{limit}} matches",
  59. find_not_found: "Phrase not found",
  60. error_version_info: "PDF.js v{{version}} (build: {{build}})",
  61. error_message: "Message: {{message}}",
  62. error_stack: "Stack: {{stack}}",
  63. error_file: "File: {{file}}",
  64. error_line: "Line: {{line}}",
  65. rendering_error: "An error occurred while rendering the page.",
  66. page_scale_width: "Page Width",
  67. page_scale_fit: "Page Fit",
  68. page_scale_auto: "Automatic Zoom",
  69. page_scale_actual: "Actual Size",
  70. page_scale_percent: "{{scale}}%",
  71. loading: "Loading…",
  72. loading_error: "An error occurred while loading the PDF.",
  73. invalid_file_error: "Invalid or corrupted PDF file.",
  74. missing_file_error: "Missing PDF file.",
  75. unexpected_response_error: "Unexpected server response.",
  76. printing_not_supported: "Warning: Printing is not fully supported by this browser.",
  77. printing_not_ready: "Warning: The PDF is not fully loaded for printing.",
  78. web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts."
  79. };
  80. function getL10nFallback(key, args) {
  81. switch (key) {
  82. case "find_match_count":
  83. key = `find_match_count[${args.total === 1 ? "one" : "other"}]`;
  84. break;
  85. case "find_match_count_limit":
  86. key = `find_match_count_limit[${args.limit === 1 ? "one" : "other"}]`;
  87. break;
  88. }
  89. return DEFAULT_L10N_STRINGS[key] || "";
  90. }
  91. function formatL10nValue(text, args) {
  92. if (!args) {
  93. return text;
  94. }
  95. return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
  96. return name in args ? args[name] : "{{" + name + "}}";
  97. });
  98. }
  99. const NullL10n = {
  100. async getLanguage() {
  101. return "en-us";
  102. },
  103. async getDirection() {
  104. return "ltr";
  105. },
  106. async get(key, args = null, fallback = getL10nFallback(key, args)) {
  107. return formatL10nValue(fallback, args);
  108. },
  109. async translate(element) {}
  110. };
  111. exports.NullL10n = NullL10n;