* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import configureLocale from './utils/configureLocale';
import exposeLibraries from './utils/exposeLibraries';
import startAjaxMonitoring from './utils/startAjaxMonitoring';
import startReactApp from './utils/startReactApp';
require('script!../libs/jquery-isolated-scroll.js');
require('script!../libs/application.js');
-configureLocale();
startAjaxMonitoring();
installGlobal();
startReactApp();
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-import moment from 'moment';
-
-const getPreferredLanguage = () =>
- (window.navigator.languages ? window.navigator.languages[0] : window.navigator.language);
-
-const configureLocale = () => {
- moment.locale(getPreferredLanguage());
-};
-
-export default configureLocale;
return messages[messageKey] != null;
}
-function getCurrentLocale() {
+export function configureMoment(language?: string) {
+ moment.locale(language || getPreferredLanguage());
+}
+
+function getPreferredLanguage() {
return window.navigator.languages ? window.navigator.languages[0] : window.navigator.language;
}
}
export function requestMessages() {
- const currentLocale = getCurrentLocale();
+ const currentLocale = getPreferredLanguage();
const cachedLocale = localStorage.getItem('l10n.locale');
-
- if (cachedLocale !== currentLocale) {
- localStorage.removeItem('l10n.timestamp');
- }
-
- const bundleTimestamp = localStorage.getItem('l10n.timestamp');
const params = {};
+
if (currentLocale) {
params.locale = currentLocale;
}
- if (bundleTimestamp !== null && checkCachedBundle()) {
- params.ts = bundleTimestamp;
+
+ if (cachedLocale === currentLocale) {
+ const bundleTimestamp = localStorage.getItem('l10n.timestamp');
+ if (bundleTimestamp !== null && checkCachedBundle()) {
+ params.ts = bundleTimestamp;
+ }
}
- return makeRequest(params).then(bundle => {
+ return makeRequest(params).then(response => {
try {
const currentTimestamp = moment().format('YYYY-MM-DDTHH:mm:ssZZ');
localStorage.setItem('l10n.timestamp', currentTimestamp);
- localStorage.setItem('l10n.locale', currentLocale);
- localStorage.setItem('l10n.bundle', JSON.stringify(bundle));
+ localStorage.setItem('l10n.locale', response.effectiveLocale);
+ localStorage.setItem('l10n.bundle', JSON.stringify(response.messages));
} catch (e) {
// do nothing
}
-
- messages = bundle;
+ configureMoment(response.effectiveLocale);
+ resetBundle(response.messages);
});
}