// We save the user language preference in the user profile, and use that to set
// the language reactively. If the user is not connected we use the language
// information provided by the browser, and default to english.

Tracker.autorun(() => {
  const currentUser = Meteor.user();
  let language;
  if (currentUser) {
    language = currentUser.profile && currentUser.profile.language;
  } else {
    language = navigator.language || navigator.userLanguage;
  }

  if (language) {
    TAPi18n.setLanguage(language);

    // XXX
    const shortLanguage = language.split('-')[0];
    T9n.setLanguage(shortLanguage);
  }
});

// We save the user language preference in the user profile, and use that to set
// the language reactively. If the user is not connected we use the language
// information provided by the browser, and default to english.

Tracker.autorun(() => {
  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) {
    TAPi18n.setLanguage(language);

    // XXX
    const shortLanguage = language.split('-')[0];
    T9n.setLanguage(shortLanguage);
  }
});

Use the navigator's language properties even if a user exists but the user has not yet choosen a profile language. If the browser provides multiple preferred languages via `navigator.languages`, select the most-preferred one.
Use the navigator's language properties even if a user exists but the user has not yet choosen a profile language. If the browser provides multiple preferred languages via `navigator.languages`, select the most-preferred one.

WKN-47
