nls.js 785 B

1234567891011121314151617181920
  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. function _format(message, args) {
  6. let result;
  7. if (args.length === 0) {
  8. result = message;
  9. }
  10. else {
  11. result = message.replace(/\{(\d+)\}/g, function (match, rest) {
  12. const index = rest[0];
  13. return typeof args[index] !== 'undefined' ? args[index] : match;
  14. });
  15. }
  16. return result;
  17. }
  18. export function localize(data, message, ...args) {
  19. return _format(message, args);
  20. }