Commit f75b3a07 authored by thierrytiti's avatar thierrytiti

I18N: detect language for MomentJS

user language detection in order to format date and time in correct
locale
parent 7c21341d
...@@ -215,35 +215,52 @@ ...@@ -215,35 +215,52 @@
// Translation machinery // Translation machinery
// --------------------- // ---------------------
this.isAvailableLocale = function (locale) { //test for MomentJS
this.testMomentLocale = function(locale){
oldlang=moment.locale();
newlang=moment.locale(locale);
return (newlang != oldlang);
}
//test for COnverseJS
this.testConverseLocale = function (locale){
return (locales[locale]);
}
//Check locale and sub locale (e.g. locale: en-US sublocale: en)
this.isAvailableLocale = function (locale,available) {
ret = null; ret = null;
if (locales[locale]) { if (available(locale)) {
ret = locales[locale]; ret = locale;
} else{ } else{
sublocale=locale.split("-")[0]; sublocale=locale.split("-")[0];
if (sublocale!=locale && locales[sublocale]) { if (sublocale!=locale && available(sublocale)) {
ret=locales[sublocale]; ret=sublocale;
} }
} }
return ret; return ret;
}; };
this.detectLocale = function () { //Check Browser information
this.detectLocale = function (testLocale) {
ret = null; ret = null;
if (window.navigator.userLanguage) { if (window.navigator.userLanguage) ret = this.isAvailableLocale(window.navigator.userLanguage, testLocale);
ret = this.isAvailableLocale(window.navigator.userLanguage); else if (window.navigator.languages && !ret) {
} else if (window.navigator.languages && !ret) {
for (var i = 0; i < window.navigator.languages.length && !ret; i++) { for (var i = 0; i < window.navigator.languages.length && !ret; i++) {
ret = this.isAvailableLocale(window.navigator.languages[i]); ret = this.isAvailableLocale(window.navigator.languages[i], testLocale);
} }
} }
else if (window.navigator.browserLanguage && !ret) ret = this.isAvailableLocale(window.navigator.browserLanguage); else if (window.navigator.browserLanguage && !ret) ret = this.isAvailableLocale(window.navigator.browserLanguage, testLocale);
else if (window.navigator.language && !ret) ret = this.isAvailableLocale(window.navigator.language); else if (window.navigator.language && !ret) ret = this.isAvailableLocale(window.navigator.language, testLocale);
else if (window.navigator.systemLanguage && !ret) ret = this.isAvailableLocale(window.navigator.systemLanguage); else if (window.navigator.systemLanguage && !ret) ret = this.isAvailableLocale(window.navigator.systemLanguage, testLocale);
else { ret = locales.en; } if (!ret) { ret = 'en'; }
return ret; return ret;
}; };
this.i18n = settings.i18n ? settings.i18n : this.detectLocale();
this.i18n = settings.i18n ? settings.i18n : locales[this.detectLocale(this.testConverseLocale)];
if (!moment.locale) moment.locale=moment.lang; //moment.lang is deprecated after 2.8.1, use moment.locale instead
moment.locale(this.detectLocale(this.testMomentLocale));
var __ = $.proxy(utils.__, this); var __ = $.proxy(utils.__, this);
var ___ = utils.___; var ___ = utils.___;
......
...@@ -16,6 +16,7 @@ Changelog ...@@ -16,6 +16,7 @@ Changelog
* I18N: Autodetection of User Locale if no i18n setting is set. [thierrytiti] * I18N: Autodetection of User Locale if no i18n setting is set. [thierrytiti]
* CSS: Fonts Path: editabable $font-path via sass/variables.scss [thierrytiti] * CSS: Fonts Path: editabable $font-path via sass/variables.scss [thierrytiti]
* Add offline pretty status to enable translation [thierrytiti] * Add offline pretty status to enable translation [thierrytiti]
* I18N: Autodetection of User Locale for MomentJS Date and Time [thierrytiti]
0.9.3 (2015-05-01) 0.9.3 (2015-05-01)
------------------ ------------------
......
...@@ -26,7 +26,7 @@ require.config({ ...@@ -26,7 +26,7 @@ require.config({
"jquery-private": "src/jquery-private", "jquery-private": "src/jquery-private",
"jquery.browser": "components/jquery.browser/dist/jquery.browser", "jquery.browser": "components/jquery.browser/dist/jquery.browser",
"jquery.easing": "components/jquery-easing-original/index", // XXX: Only required for https://conversejs.org website "jquery.easing": "components/jquery-easing-original/index", // XXX: Only required for https://conversejs.org website
"moment": "components/momentjs/moment", "moment": "components/momentjs/min/moment-with-langs",
"strophe-base64": "components/strophejs/src/base64", "strophe-base64": "components/strophejs/src/base64",
"strophe-bosh": "components/strophejs/src/bosh", "strophe-bosh": "components/strophejs/src/bosh",
"strophe-core": "components/strophejs/src/core", "strophe-core": "components/strophejs/src/core",
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
<script type="text/javascript" src="components/backbone//backbone.js"></script> <script type="text/javascript" src="components/backbone//backbone.js"></script>
<script type="text/javascript" src="components/backbone.browserStorage/backbone.browserStorage.js"></script> <script type="text/javascript" src="components/backbone.browserStorage/backbone.browserStorage.js"></script>
<script type="text/javascript" src="components/backbone.overview/backbone.overview.js"></script> <script type="text/javascript" src="components/backbone.overview/backbone.overview.js"></script>
<script type="text/javascript" src="components/momentjs/moment.js"></script> <script type="text/javascript" src="components/momentjs/min/moment-with-langs.js"></script>
<script type="text/javascript" src="components/jquery.browser/dist/jquery.browser.js"></script> <script type="text/javascript" src="components/jquery.browser/dist/jquery.browser.js"></script>
<script type="text/javascript" src="components/typeahead.js/index.js"></script> <script type="text/javascript" src="components/typeahead.js/index.js"></script>
<script type="text/javascript" src="components/jed/jed.js"></script> <script type="text/javascript" src="components/jed/jed.js"></script>
......
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