From 1c206d0d367cbb4b6aa2e350ce944397bd48b988 Mon Sep 17 00:00:00 2001 From: David Renshaw Date: Thu, 10 Nov 2016 10:10:06 -0500 Subject: Fix startup for clients using Finnish and Chinese. --- client/lib/i18n.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'client') diff --git a/client/lib/i18n.js b/client/lib/i18n.js index a03fb398..b8b8609d 100644 --- a/client/lib/i18n.js +++ b/client/lib/i18n.js @@ -14,8 +14,14 @@ Tracker.autorun(() => { if (language) { TAPi18n.setLanguage(language); - // XXX - const shortLanguage = language.split('-')[0]; - T9n.setLanguage(shortLanguage); + // For languages such as Finnish (Suomi) that are not supported by meteor-accounts-t9n, + // the following may throw an exception. On the initial run of this `autorun()` callback, + // such an exception could cause the entire app to fail to load. Therefore, we catch + // the exception and log it as an error. + try { + T9n.setLanguage(language); + } catch (e) { + console.error(e); + } } }); -- cgit v1.2.3-1-g7c22 From f56c55e75c657d6348c4231779d410f4cdea7a04 Mon Sep 17 00:00:00 2001 From: David Renshaw Date: Mon, 14 Nov 2016 21:26:01 -0500 Subject: Wait until Meteor.startup() to set the language. --- client/lib/i18n.js | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'client') diff --git a/client/lib/i18n.js b/client/lib/i18n.js index b8b8609d..f2709d15 100644 --- a/client/lib/i18n.js +++ b/client/lib/i18n.js @@ -2,26 +2,19 @@ // 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); +Meteor.startup(() => { + Tracker.autorun(() => { + const currentUser = Meteor.user(); + let language; + if (currentUser) { + language = currentUser.profile && currentUser.profile.language; + } else { + language = navigator.language || navigator.userLanguage; + } - // For languages such as Finnish (Suomi) that are not supported by meteor-accounts-t9n, - // the following may throw an exception. On the initial run of this `autorun()` callback, - // such an exception could cause the entire app to fail to load. Therefore, we catch - // the exception and log it as an error. - try { + if (language) { + TAPi18n.setLanguage(language); T9n.setLanguage(language); - } catch (e) { - console.error(e); } - } + }); }); -- cgit v1.2.3-1-g7c22 From 4b248151c3b1fbb763b5d95cd729fc99828be382 Mon Sep 17 00:00:00 2001 From: David Renshaw Date: Mon, 14 Nov 2016 22:06:58 -0500 Subject: always fall back to navigator.language if user.profile.language is not set --- client/lib/i18n.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'client') diff --git a/client/lib/i18n.js b/client/lib/i18n.js index f2709d15..34a789e1 100644 --- a/client/lib/i18n.js +++ b/client/lib/i18n.js @@ -6,8 +6,8 @@ Meteor.startup(() => { Tracker.autorun(() => { const currentUser = Meteor.user(); let language; - if (currentUser) { - language = currentUser.profile && currentUser.profile.language; + if (currentUser && currentUser.profile && currentUser.profile.language) { + language = currentUser.profile.language; } else { language = navigator.language || navigator.userLanguage; } -- cgit v1.2.3-1-g7c22