Bläddra i källkod

Hopeful fix for i18n not working in `onRendered()`

* Remove the i18n initialization code from an `autorun()` block
* Add some console statements to help with debugging production.
* Add functions to `Boards` for label colors and color mapping
John R. Supplee 4 år sedan
förälder
incheckning
e4f50d4713
4 ändrade filer med 42 tillägg och 31 borttagningar
  1. 7 8
      client/components/main/globalSearch.js
  2. 17 17
      client/lib/i18n.js
  3. 12 0
      models/boards.js
  4. 6 6
      server/publications/cards.js

+ 7 - 8
client/components/main/globalSearch.js

@@ -78,12 +78,10 @@ BlazeComponent.extendComponent({
   onRendered() {
     Meteor.subscribe('setting');
 
-    this.colorMap = {};
-    for (const color of Boards.simpleSchema()._schema['labels.$.color']
-      .allowedValues) {
-      this.colorMap[TAPi18n.__(`color-${color}`)] = color;
-    }
-    // // eslint-disable-next-line no-console
+    // eslint-disable-next-line no-console
+    console.log('lang:', TAPi18n.getLanguage());
+    this.colorMap = Boards.colorMap();
+    // eslint-disable-next-line no-console
     // console.log('colorMap:', this.colorMap);
 
     if (Session.get('globalQuery')) {
@@ -296,13 +294,14 @@ BlazeComponent.extendComponent({
         if (m.groups.operator) {
           op = m.groups.operator.toLowerCase();
         } else {
-          op = m.groups.abbrev;
+          op = m.groups.abbrev.toLowerCase();
         }
         if (operatorMap.hasOwnProperty(op)) {
           let value = m.groups.value;
           if (operatorMap[op] === 'labels') {
             if (value in this.colorMap) {
               value = this.colorMap[value];
+              // console.log('found color:', value);
             }
           } else if (
             ['dueAt', 'createdAt', 'modifiedAt'].includes(operatorMap[op])
@@ -388,7 +387,7 @@ BlazeComponent.extendComponent({
     params.text = text;
 
     // eslint-disable-next-line no-console
-    // console.log('params:', params);
+    console.log('params:', params);
 
     this.queryParams = params;
 

+ 17 - 17
client/lib/i18n.js

@@ -4,24 +4,24 @@
 
 Meteor.startup(() => {
   TAPi18n.conf.i18n_files_route = Meteor._relativeToSiteRootUrl('/tap-i18n');
-  Tracker.autorun(() => {
-    const currentUser = Meteor.user();
-    let language;
-    if (currentUser) {
-      language = currentUser.profile && currentUser.profile.language;
-    }
+  const currentUser = Meteor.user();
+  let language;
+  if (currentUser) {
+    language = currentUser.profile && currentUser.profile.language;
+  }
 
-    if (!language) {
-      if (navigator.languages) {
-        language = navigator.languages[0];
-      } else {
-        language = navigator.language || navigator.userLanguage;
-      }
+  if (!language) {
+    if (navigator.languages) {
+      language = navigator.languages[0];
+    } else {
+      language = navigator.language || navigator.userLanguage;
     }
+  }
 
-    if (language) {
-      TAPi18n.setLanguage(language);
-      T9n.setLanguage(language);
-    }
-  });
+  if (language) {
+    TAPi18n.setLanguage(language);
+    // eslint-disable-next-line no-console
+    console.log('language set!');
+    T9n.setLanguage(language);
+  }
 });

+ 12 - 0
models/boards.js

@@ -1318,6 +1318,18 @@ Boards.userBoardIds = (userId, archived = false, selector = {}) => {
   });
 };
 
+Boards.colorMap = () => {
+  const colors = {};
+  for (const color of Boards.labelColors()) {
+    colors[TAPi18n.__(`color-${color}`)] = color;
+  }
+  return colors;
+};
+
+Boards.labelColors = () => {
+  return _.clone(Boards.simpleSchema()._schema['labels.$.color'].allowedValues);
+};
+
 if (Meteor.isServer) {
   Boards.allow({
     insert: Meteor.userId,

+ 6 - 6
server/publications/cards.js

@@ -200,11 +200,7 @@ Meteor.publish('globalSearch', function(sessionId, queryParams) {
         comments: [],
       };
 
-      this.colorMap = {};
-      for (const color of Boards.simpleSchema()._schema['labels.$.color']
-        .allowedValues) {
-        this.colorMap[TAPi18n.__(`color-${color}`)] = color;
-      }
+      this.colorMap = Boards.colorMap();
     }
 
     hasErrors() {
@@ -234,7 +230,11 @@ Meteor.publish('globalSearch', function(sessionId, queryParams) {
         });
       });
       this.notFound.labels.forEach(label => {
-        messages.push({ tag: 'label-not-found', value: label, color: true });
+        messages.push({
+          tag: 'label-not-found',
+          value: label,
+          color: Boards.labelColors().includes(label),
+        });
       });
       this.notFound.users.forEach(user => {
         messages.push({ tag: 'user-username-not-found', value: user });