msg.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * @license
  3. * Visual Blocks Editor
  4. *
  5. * Copyright 2013 Google Inc.
  6. * https://developers.google.com/blockly/
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. */
  20. /**
  21. * @fileoverview Empty name space for the Message singleton.
  22. * @author scr@google.com (Sheridan Rawlins)
  23. */
  24. 'use strict';
  25. /**
  26. * Name space for the Msg singleton.
  27. * Msg gets populated in the message files.
  28. */
  29. goog.provide('Blockly.Msg');
  30. /**
  31. * Back up original getMsg function.
  32. * @type {!Function}
  33. */
  34. goog.getMsgOrig = goog.getMsg;
  35. /**
  36. * Gets a localized message.
  37. * Overrides the default Closure function to check for a Blockly.Msg first.
  38. * Used infrequently, only known case is TODAY button in date picker.
  39. * @param {string} str Translatable string, places holders in the form {$foo}.
  40. * @param {Object<string, string>=} opt_values Maps place holder name to value.
  41. * @return {string} message with placeholders filled.
  42. * @suppress {duplicate}
  43. */
  44. goog.getMsg = function(str, opt_values) {
  45. var key = goog.getMsg.blocklyMsgMap[str];
  46. if (key) {
  47. str = Blockly.Msg[key];
  48. }
  49. return goog.getMsgOrig(str, opt_values);
  50. };
  51. /**
  52. * Mapping of Closure messages to Blockly.Msg names.
  53. */
  54. goog.getMsg.blocklyMsgMap = {
  55. 'Today': 'TODAY'
  56. };