templates.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  3. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. // FIXME: maybe it would be better to dynamically assemble the first
  5. // argument to define() here to include the localized module:
  6. define(["util", "require"], function (util, require) {
  7. var assert = util.assert;
  8. function clean(t) {
  9. // Removes <% /* ... */ %> comments:
  10. t = t.replace(/[<][%]\s*\/\*[\S\s\r\n]*\*\/\s*[%][>]/, "");
  11. t = util.trim(t);
  12. t = t.replace(/http:\/\/localhost:8080/g, TogetherJS.baseUrl);
  13. t = t.replace(/TOOL_NAME/g, '<span class="togetherjs-tool-name">TogetherJS</span>');
  14. t = t.replace(/SITE_NAME/g, '<strong class="togetherjs-site-name">[site name]</strong>');
  15. t = t.replace(/TOOL_SITE_LINK/g, '<a href="https://togetherjs.com/" target="_blank"><span class="togetherjs-tool-name">TogetherJS</span></a>');
  16. return t;
  17. }
  18. var lang = TogetherJS.getConfig("lang") || "en-US";
  19. var moduleName = "templates-" + lang;
  20. var templatesLang;
  21. require([moduleName], function (mod) {
  22. templatesLang = mod;
  23. });
  24. return function (resourceName) {
  25. // Sometimes require([moduleName]) doesn't return even after the
  26. // module has been loaded, but this sync version of require() will
  27. // pick up the module in that case:
  28. if (! templatesLang) {
  29. try {
  30. templatesLang = require(moduleName);
  31. } catch (e) {
  32. console.warn("Error requiring module:", e);
  33. }
  34. }
  35. assert(templatesLang, "Templates not yet loaded");
  36. return clean(templatesLang[resourceName]);
  37. };
  38. });