common.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. "use strict";
  2. /* --------------------------------------------------------------------------------------------
  3. * Copyright (c) Microsoft Corporation. All rights reserved.
  4. * Licensed under the MIT License. See License.txt in the project root for license information.
  5. * ------------------------------------------------------------------------------------------ */
  6. Object.defineProperty(exports, "__esModule", { value: true });
  7. exports.config = exports.loadMessageBundle = exports.localize = exports.format = exports.setPseudo = exports.isPseudo = exports.isDefined = exports.BundleFormat = exports.MessageFormat = void 0;
  8. var ral_1 = require("./ral");
  9. var MessageFormat;
  10. (function (MessageFormat) {
  11. MessageFormat["file"] = "file";
  12. MessageFormat["bundle"] = "bundle";
  13. MessageFormat["both"] = "both";
  14. })(MessageFormat = exports.MessageFormat || (exports.MessageFormat = {}));
  15. var BundleFormat;
  16. (function (BundleFormat) {
  17. // the nls.bundle format
  18. BundleFormat["standalone"] = "standalone";
  19. BundleFormat["languagePack"] = "languagePack";
  20. })(BundleFormat = exports.BundleFormat || (exports.BundleFormat = {}));
  21. var LocalizeInfo;
  22. (function (LocalizeInfo) {
  23. function is(value) {
  24. var candidate = value;
  25. return candidate && isDefined(candidate.key) && isDefined(candidate.comment);
  26. }
  27. LocalizeInfo.is = is;
  28. })(LocalizeInfo || (LocalizeInfo = {}));
  29. function isDefined(value) {
  30. return typeof value !== 'undefined';
  31. }
  32. exports.isDefined = isDefined;
  33. exports.isPseudo = false;
  34. function setPseudo(pseudo) {
  35. exports.isPseudo = pseudo;
  36. }
  37. exports.setPseudo = setPseudo;
  38. function format(message, args) {
  39. var result;
  40. if (exports.isPseudo) {
  41. // FF3B and FF3D is the Unicode zenkaku representation for [ and ]
  42. message = '\uFF3B' + message.replace(/[aouei]/g, '$&$&') + '\uFF3D';
  43. }
  44. if (args.length === 0) {
  45. result = message;
  46. }
  47. else {
  48. result = message.replace(/\{(\d+)\}/g, function (match, rest) {
  49. var index = rest[0];
  50. var arg = args[index];
  51. var replacement = match;
  52. if (typeof arg === 'string') {
  53. replacement = arg;
  54. }
  55. else if (typeof arg === 'number' || typeof arg === 'boolean' || arg === void 0 || arg === null) {
  56. replacement = String(arg);
  57. }
  58. return replacement;
  59. });
  60. }
  61. return result;
  62. }
  63. exports.format = format;
  64. function localize(_key, message) {
  65. var args = [];
  66. for (var _i = 2; _i < arguments.length; _i++) {
  67. args[_i - 2] = arguments[_i];
  68. }
  69. return format(message, args);
  70. }
  71. exports.localize = localize;
  72. function loadMessageBundle(file) {
  73. return ral_1.default().loadMessageBundle(file);
  74. }
  75. exports.loadMessageBundle = loadMessageBundle;
  76. function config(opts) {
  77. return ral_1.default().config(opts);
  78. }
  79. exports.config = config;
  80. //# sourceMappingURL=common.js.map