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