layouts.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. BlazeLayout.setRoot('body');
  2. const i18nTagToT9n = (i18nTag) => {
  3. // t9n/i18n tags are same now, see: https://github.com/softwarerero/meteor-accounts-t9n/pull/129
  4. // but we keep this conversion function here, to be aware that that they are different system.
  5. return i18nTag;
  6. };
  7. Template.userFormsLayout.onRendered(() => {
  8. const i18nTag = navigator.language;
  9. if (i18nTag) {
  10. T9n.setLanguage(i18nTagToT9n(i18nTag));
  11. }
  12. EscapeActions.executeAll();
  13. });
  14. Template.userFormsLayout.helpers({
  15. languages() {
  16. return _.map(TAPi18n.getLanguages(), (lang, code) => {
  17. return {
  18. tag: code,
  19. name: lang.name === 'br' ? 'Brezhoneg' : lang.name === 'ig' ? 'Igbo' : lang.name,
  20. };
  21. }).sort(function(a, b) {
  22. if (a.name === b.name) {
  23. return 0;
  24. } else {
  25. return a.name > b.name ? 1 : -1;
  26. }
  27. });
  28. },
  29. isCurrentLanguage() {
  30. const t9nTag = i18nTagToT9n(this.tag);
  31. const curLang = T9n.getLanguage() || 'en';
  32. return t9nTag === curLang;
  33. },
  34. });
  35. Template.userFormsLayout.events({
  36. 'change .js-userform-set-language'(evt) {
  37. const i18nTag = $(evt.currentTarget).val();
  38. T9n.setLanguage(i18nTagToT9n(i18nTag));
  39. evt.preventDefault();
  40. },
  41. });
  42. Template.defaultLayout.events({
  43. 'click .js-close-modal': () => {
  44. Modal.close();
  45. },
  46. });