Parcourir la source

convert user.lang for current user data

Yuki Takei il y a 5 ans
Parent
commit
668d4ae3d0
2 fichiers modifiés avec 14 ajouts et 1 suppressions
  1. 13 0
      src/server/util/middlewares.js
  2. 1 1
      src/server/views/layout/layout.html

+ 13 - 0
src/server/util/middlewares.js

@@ -8,6 +8,10 @@ const pathUtils = require('growi-commons').pathUtils;
 const md5 = require('md5');
 const md5 = require('md5');
 const entities = require('entities');
 const entities = require('entities');
 
 
+const { getLocaleAliasToIdMap } = require('@commons/util/locale-utils');
+
+const aliasToIdMap = getLocaleAliasToIdMap();
+
 module.exports = (crowi) => {
 module.exports = (crowi) => {
   const { configManager, appService } = crowi;
   const { configManager, appService } = crowi;
 
 
@@ -154,6 +158,15 @@ module.exports = (crowi) => {
         return list.slice(start, end);
         return list.slice(start, end);
       });
       });
 
 
+      /**
+       * convert locale alias to corrent locale id for backward compatibility -- 2020.06.21 Yuki Takei
+       */
+      swig.setFilter('convertOldLangPropertyToLocaleId', (user) => {
+        const { lang: userLang } = user;
+        user.lang = aliasToIdMap[userLang] || userLang;
+        return user;
+      });
+
       next();
       next();
     };
     };
   };
   };

+ 1 - 1
src/server/views/layout/layout.html

@@ -163,7 +163,7 @@
 
 
 {% if user != null %}
 {% if user != null %}
   <script type="application/json" id="growi-current-user">
   <script type="application/json" id="growi-current-user">
-  {{ user|json|safe|preventXss }}
+  {{ user|convertOldLangPropertyToLocaleId|json|safe|preventXss }}
   </script>
   </script>
 {% endif %}
 {% endif %}