translator.js 985 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Licensed Materials - Property of IBM
  3. *
  4. * IBM Cognos Products: SHARE
  5. *
  6. * (C) Copyright IBM Corp. 2015, 2016
  7. *
  8. * US Government Users Restricted Rights - Use, duplication or disclosure
  9. * restricted by GSA ADP Schedule Contract with IBM Corp.
  10. */
  11. define(["i18n!bi/sharecommon/nls/share_client", "polyglot"], (function(localeResources) {
  12. var translator = {};
  13. translator.options = {
  14. verbose: false
  15. };
  16. translator.NOT_TRANSLATED = "__NOT_TRANSLATED__";
  17. polyglot = new Polyglot({
  18. phrases: localeResources
  19. });
  20. /**
  21. * Translates a key in the current locale
  22. * @param key message key
  23. * @param interpolation key-value pairs for interpolation
  24. */
  25. translator.translate = function(key,interpolation) {
  26. var translated = polyglot.t(key,interpolation);
  27. if (translator.options.verbose) {
  28. if (translated === key) {
  29. translated = translator.NOT_TRANSLATED + "(" + key + ")";
  30. }
  31. }
  32. return translated;
  33. };
  34. return translator;
  35. }));