Commit baee4750 authored by Curtis Adam's avatar Curtis Adam

Use profile.locale instead of selectedLanguage to check the users saved language

parent b6b5426b
......@@ -16,6 +16,7 @@ if (Meteor.isServer) {
'profile.birthname': 1,
'profile.givenname': 1,
'profile.title': 1,
'profile.locale': 1,
'email': 1,
'services': 1,
'lvl': 1,
......@@ -46,6 +47,7 @@ if (Meteor.isServer) {
'profile.birthname': 1,
'profile.givenname': 1,
'profile.title': 1,
'profile.locale': 1,
'email': 1,
'services': 1,
'lvl': 1,
......@@ -180,7 +182,7 @@ Meteor.methods({
}
return name;
},
initUser: function () {
initUser: function (userLanguage) {
if (this.userId && !Roles.userIsInRole(this.userId, 'blocked')) {
var user = Meteor.users.findOne({
_id: Meteor.userId(),
......@@ -201,7 +203,8 @@ Meteor.methods({
daysInRow: 0,
selectedColorTheme: "default",
mailNotification: true,
webNotification: false
webNotification: false,
"profile.locale": userLanguage
}
});
}
......@@ -351,7 +354,7 @@ Meteor.methods({
Meteor.users.update(id, {
$set: {
"selectedLanguage": selectedLanguage
"profile.locale": selectedLanguage
}
});
},
......
......@@ -5,18 +5,7 @@ import {Meteor} from "meteor/meteor";
export function getUserLanguage() {
if (Meteor.userId()) {
let language = Meteor.users.findOne(Meteor.userId()).selectedLanguage;
if (language !== undefined) {
return language;
} else {
let navigatorLanguage = navigator.language.substr(0, 2);
switch (navigatorLanguage) {
case "de":
return "de";
default:
return "en";
}
}
return Meteor.users.findOne(Meteor.userId()).profile.locale;
} else {
return navigator.language.substr(0, 2);
}
......
......@@ -591,6 +591,22 @@ Meteor.startup(function () {
);
}
let users = Meteor.users.find({selectedLanguage: {$exists: true}}).fetch();
for (let i = 0; i < users.length; i++) {
Meteor.users.update({
_id: users[i]._id
},
{
$set: {
"profile.locale": users[i].selectedLanguage
},
$unset: {
selectedLanguage: ""
}
}
);
}
ColorThemes.remove({});
for (let theme in themes) {
if (themes.hasOwnProperty(theme)) {
......
......@@ -18,6 +18,7 @@ import "../admin/admin.js";
import "../access_denied/access_denied.js";
import "../first_login/first_login.js";
import "../../api/groundDB.js";
import {getUserLanguage} from "../../startup/client/i18n";
Meteor.subscribe("Users");
Meteor.subscribe("notifications");
......@@ -232,7 +233,7 @@ Template.main.helpers({
Template.main.onRendered(function () {
Session.set("searchValue", undefined);
Meteor.call("initUser");
Meteor.call("initUser", getUserLanguage());
adjustSearchResultWindowSize();
$(window).resize(function () {
adjustSearchResultWindowSize();
......
......@@ -88,7 +88,7 @@ Template.profileSettings.helpers({
},
/** Function returns "selected" when the value of the selectedLanguage and the input _id are the same */
getSelectedLanguage: function (id) {
if (id === Meteor.users.findOne(Meteor.userId()).selectedLanguage) {
if (id === Meteor.users.findOne(Meteor.userId()).profile.locale) {
return "selected";
}
},
......@@ -120,7 +120,7 @@ Template.profileSettings.helpers({
Template.profileSettings.onDestroyed(function () {
// Go back to last saved Theme
Session.set("theme", Meteor.users.findOne(Meteor.userId()).selectedColorTheme);
Session.set("language", Meteor.users.findOne(Meteor.userId()).selectedLanguage);
Session.set("language", Meteor.users.findOne(Meteor.userId()).profile.locale);
});
Template.profileSettings.onCreated(function () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment