layouts.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. const tag = code;
  18. let name = lang.name;
  19. if (lang.name === 'br') {
  20. name = 'Brezhoneg';
  21. } else if (lang.name === 'ig') {
  22. name = 'Igbo';
  23. }
  24. return { tag, name };
  25. }).sort(function(a, b) {
  26. if (a.name === b.name) {
  27. return 0;
  28. } else {
  29. return a.name > b.name ? 1 : -1;
  30. }
  31. });
  32. },
  33. isCurrentLanguage() {
  34. const t9nTag = i18nTagToT9n(this.tag);
  35. const curLang = T9n.getLanguage() || 'en';
  36. return t9nTag === curLang;
  37. },
  38. });
  39. Template.userFormsLayout.events({
  40. 'change .js-userform-set-language'(evt) {
  41. const i18nTag = $(evt.currentTarget).val();
  42. T9n.setLanguage(i18nTagToT9n(i18nTag));
  43. evt.preventDefault();
  44. },
  45. });
  46. Template.defaultLayout.events({
  47. 'click .js-close-modal': () => {
  48. Modal.close();
  49. },
  50. });