Guest User

Untitled

a guest
Dec 14th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. {
  2. en: {
  3. name: "english name",
  4. content: "english content"
  5. },
  6. it: {
  7. name: "italian name",
  8. content: "italian content"
  9. },
  10. //since images are the same for both, are not nested
  11. images: {
  12. mainImage: "dataURL",
  13. mainThumb: "dataURL"
  14. }
  15. }
  16.  
  17. Meteor.publish("elementsCurrentLang", function(currentLang) {
  18.  
  19. var projection = {
  20. images: 1
  21. };
  22.  
  23. projection[currentLang] = 1;
  24.  
  25. return Elements.find({}, projection);
  26. });
  27.  
  28. Router.route('/eng/elements', {
  29. waitOn: function() {
  30. return Meteor.subscribe("municipalitiesCurrentLang", Session.get('currentLang'));
  31. },
  32. action: function() {
  33. this.layout('ApplicationLayout');
  34. this.render('elements');
  35. }
  36. });
  37.  
  38. Template.elements.helpers({
  39. elements: function() {
  40. var elements = Elements.find();
  41. var currentLang = Session.get('currentLang');
  42. var resultList = [];
  43.  
  44. elements.forEach(function(element, index) {
  45. var element = {
  46. name: element[currentLang].name,
  47. content: element[currentLang].nameUrl,
  48. images: element.images
  49. };
  50.  
  51. resultList.push(element);
  52. });
  53.  
  54. return resultList;
  55. }
  56. });
  57.  
  58. <h1>{{name}}</h1>
  59. <p>{{content}}</p>
  60.  
  61. en.i18n.json:
  62. {
  63. "hello": "hello"
  64. }
  65. fr.i18n.json:
  66. {
  67. "hello": "bonjour"
  68. }
  69.  
  70. {{_ "hello" }}
  71.  
  72. TAPi18n.setLanguage(getUserLanguage())
  73. //getUserLanguage() <- my function to get the current langage in the user profile or
  74. the one used by the navigator
Add Comment
Please, Sign In to add comment