layouts.js 1.3 KB

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