Commit 93de11d1 authored by JC Brand's avatar JC Brand

Dynamically load the dayjs translation.

Also, remove the Promise polyfill. We don't support browsers which don't support promises.
parent 9f054dd7
...@@ -4990,7 +4990,8 @@ ...@@ -4990,7 +4990,8 @@
"es6-promise": { "es6-promise": {
"version": "4.2.8", "version": "4.2.8",
"resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgz", "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgz",
"integrity": "sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==" "integrity": "sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==",
"dev": true
}, },
"es6-promisify": { "es6-promisify": {
"version": "5.0.0", "version": "5.0.0",
......
...@@ -29,7 +29,7 @@ import tpl_toolbar_fileupload from "templates/toolbar_fileupload.html"; ...@@ -29,7 +29,7 @@ import tpl_toolbar_fileupload from "templates/toolbar_fileupload.html";
import tpl_user_details_modal from "templates/user_details_modal.html"; import tpl_user_details_modal from "templates/user_details_modal.html";
import xss from "xss/dist/xss"; import xss from "xss/dist/xss";
const { $msg, Backbone, Promise, Strophe, _, sizzle, dayjs } = converse.env; const { $msg, Backbone, Strophe, _, sizzle, dayjs } = converse.env;
const u = converse.env.utils; const u = converse.env.utils;
......
...@@ -17,7 +17,7 @@ import tpl_controlbox_toggle from "templates/controlbox_toggle.html"; ...@@ -17,7 +17,7 @@ import tpl_controlbox_toggle from "templates/controlbox_toggle.html";
import tpl_login_panel from "templates/login_panel.html"; import tpl_login_panel from "templates/login_panel.html";
const CHATBOX_TYPE = 'chatbox'; const CHATBOX_TYPE = 'chatbox';
const { Strophe, Backbone, Promise, _, dayjs } = converse.env; const { Strophe, Backbone, _, dayjs } = converse.env;
const u = converse.env.utils; const u = converse.env.utils;
const CONNECTION_STATUS_CSS_CLASS = { const CONNECTION_STATUS_CSS_CLASS = {
......
...@@ -16,7 +16,7 @@ import tpl_toggle_chats from "templates/toggle_chats.html"; ...@@ -16,7 +16,7 @@ import tpl_toggle_chats from "templates/toggle_chats.html";
import tpl_trimmed_chat from "templates/trimmed_chat.html"; import tpl_trimmed_chat from "templates/trimmed_chat.html";
const { _ , Backbone, Promise, Strophe, dayjs } = converse.env; const { _ , Backbone, Strophe, dayjs } = converse.env;
const u = converse.env.utils; const u = converse.env.utils;
converse.plugins.add('converse-minimize', { converse.plugins.add('converse-minimize', {
......
...@@ -43,7 +43,7 @@ import tpl_spinner from "templates/spinner.html"; ...@@ -43,7 +43,7 @@ import tpl_spinner from "templates/spinner.html";
import xss from "xss/dist/xss"; import xss from "xss/dist/xss";
const { Backbone, Promise, Strophe, dayjs, sizzle, _, $iq, $msg, $pres } = converse.env; const { Backbone, Strophe, dayjs, sizzle, _, $iq, $msg, $pres } = converse.env;
const u = converse.env.utils; const u = converse.env.utils;
const ROLES = ['moderator', 'participant', 'visitor']; const ROLES = ['moderator', 'participant', 'visitor'];
......
...@@ -13,7 +13,7 @@ import BrowserStorage from "backbone.browserStorage"; ...@@ -13,7 +13,7 @@ import BrowserStorage from "backbone.browserStorage";
import converse from "@converse/headless/converse-core"; import converse from "@converse/headless/converse-core";
import tpl_toolbar_omemo from "templates/toolbar_omemo.html"; import tpl_toolbar_omemo from "templates/toolbar_omemo.html";
const { Backbone, Promise, Strophe, dayjs, sizzle, $build, $iq, $msg, _ } = converse.env; const { Backbone, Strophe, dayjs, sizzle, $build, $iq, $msg, _ } = converse.env;
const u = converse.env.utils; const u = converse.env.utils;
Strophe.addNamespace('OMEMO_DEVICELIST', Strophe.NS.OMEMO+".devicelist"); Strophe.addNamespace('OMEMO_DEVICELIST', Strophe.NS.OMEMO+".devicelist");
......
...@@ -18,8 +18,7 @@ import tpl_profile_modal from "templates/profile_modal.html"; ...@@ -18,8 +18,7 @@ import tpl_profile_modal from "templates/profile_modal.html";
import tpl_profile_view from "templates/profile_view.html"; import tpl_profile_view from "templates/profile_view.html";
import tpl_status_option from "templates/status_option.html"; import tpl_status_option from "templates/status_option.html";
const { Strophe, Backbone, utils, _, dayjs, sizzle } = converse.env;
const { Strophe, Backbone, Promise, utils, _, dayjs, sizzle } = converse.env;
const u = converse.env.utils; const u = converse.env.utils;
......
...@@ -16,7 +16,7 @@ import muc from "@converse/headless/converse-muc"; ...@@ -16,7 +16,7 @@ import muc from "@converse/headless/converse-muc";
import tpl_rooms_list from "templates/rooms_list.html"; import tpl_rooms_list from "templates/rooms_list.html";
import tpl_rooms_list_item from "templates/rooms_list_item.html" import tpl_rooms_list_item from "templates/rooms_list_item.html"
const { Backbone, Promise, Strophe, sizzle, _ } = converse.env; const { Backbone, Strophe, sizzle, _ } = converse.env;
const u = converse.env.utils; const u = converse.env.utils;
......
...@@ -13,7 +13,7 @@ import "@converse/headless/converse-muc"; ...@@ -13,7 +13,7 @@ import "@converse/headless/converse-muc";
import BrowserStorage from "backbone.browserStorage"; import BrowserStorage from "backbone.browserStorage";
import converse from "@converse/headless/converse-core"; import converse from "@converse/headless/converse-core";
const { Backbone, Promise, Strophe, $iq, sizzle, _ } = converse.env; const { Backbone, Strophe, $iq, sizzle, _ } = converse.env;
const u = converse.env.utils; const u = converse.env.utils;
......
...@@ -12,7 +12,7 @@ import BrowserStorage from "backbone.browserStorage"; ...@@ -12,7 +12,7 @@ import BrowserStorage from "backbone.browserStorage";
import converse from "./converse-core"; import converse from "./converse-core";
import filesize from "filesize"; import filesize from "filesize";
const { $msg, Backbone, Promise, Strophe, dayjs, sizzle, utils, _ } = converse.env; const { $msg, Backbone, Strophe, dayjs, sizzle, utils, _ } = converse.env;
const u = converse.env.utils; const u = converse.env.utils;
Strophe.addNamespace('MESSAGE_CORRECT', 'urn:xmpp:message-correct:0'); Strophe.addNamespace('MESSAGE_CORRECT', 'urn:xmpp:message-correct:0');
......
...@@ -11,7 +11,6 @@ import 'strophe.js/src/websocket'; ...@@ -11,7 +11,6 @@ import 'strophe.js/src/websocket';
import * as strophe from 'strophe.js/src/core'; import * as strophe from 'strophe.js/src/core';
import Backbone from 'backbone'; import Backbone from 'backbone';
import BrowserStorage from 'backbone.browserStorage'; import BrowserStorage from 'backbone.browserStorage';
import Promise from 'es6-promise/dist/es6-promise.auto';
import _ from './lodash.noconflict'; import _ from './lodash.noconflict';
import advancedFormat from 'dayjs/plugin/advancedFormat'; import advancedFormat from 'dayjs/plugin/advancedFormat';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
...@@ -832,10 +831,15 @@ _converse.initialize = async function (settings, callback) { ...@@ -832,10 +831,15 @@ _converse.initialize = async function (settings, callback) {
}); });
/* Localisation */ /* Localisation */
if (i18n !== undefined) { if (i18n === undefined || _converse.isTestEnv()) {
i18n.setLocales(settings.i18n, _converse);
} else {
_converse.locale = 'en'; _converse.locale = 'en';
} else {
try {
_converse.locale = i18n.getLocale(settings.i18n, _converse.locales);
await i18n.fetchTranslations(_converse);
} catch (e) {
_converse.log(e.message, Strophe.LogLevel.FATAL);
}
} }
// Module-level variables // Module-level variables
...@@ -1331,18 +1335,12 @@ _converse.initialize = async function (settings, callback) { ...@@ -1331,18 +1335,12 @@ _converse.initialize = async function (settings, callback) {
this.connection = settings.connection; this.connection = settings.connection;
} }
await finishInitialization();
if (_converse.isTestEnv()) { if (_converse.isTestEnv()) {
await finishInitialization();
return _converse; return _converse;
} else if (i18n !== undefined) { } else {
try { return init_promise;
await i18n.fetchTranslations(_converse.locale, _converse.locales);
} catch (e) {
_converse.log(e.message, Strophe.LogLevel.FATAL);
}
} }
await finishInitialization();
return init_promise;
}; };
/** /**
......
...@@ -12,7 +12,7 @@ import BrowserStorage from "backbone.browserStorage"; ...@@ -12,7 +12,7 @@ import BrowserStorage from "backbone.browserStorage";
import converse from "./converse-core"; import converse from "./converse-core";
import sizzle from "sizzle"; import sizzle from "sizzle";
const { Backbone, Promise, Strophe, $iq, utils, _ } = converse.env; const { Backbone, Strophe, $iq, utils, _ } = converse.env;
converse.plugins.add('converse-disco', { converse.plugins.add('converse-disco', {
......
...@@ -23,7 +23,7 @@ const MUC_ROLE_WEIGHTS = { ...@@ -23,7 +23,7 @@ const MUC_ROLE_WEIGHTS = {
'none': 2, 'none': 2,
}; };
const { Strophe, Backbone, Promise, $iq, $build, $msg, $pres, sizzle, _ } = converse.env; const { Strophe, Backbone, $iq, $build, $msg, $pres, sizzle, _ } = converse.env;
// Add Strophe Namespaces // Add Strophe Namespaces
Strophe.addNamespace('MUC_ADMIN', Strophe.NS.MUC + "#admin"); Strophe.addNamespace('MUC_ADMIN', Strophe.NS.MUC + "#admin");
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
import "./converse-disco"; import "./converse-disco";
import converse from "./converse-core"; import converse from "./converse-core";
const { Strophe, Backbone, Promise, $iq, $build, $msg, $pres, dayjs, _ } = converse.env; const { Strophe, Backbone, $iq, $build, $msg, $pres, dayjs, _ } = converse.env;
Strophe.addNamespace('PUBSUB_ERROR', Strophe.NS.PUBSUB+"#errors"); Strophe.addNamespace('PUBSUB_ERROR', Strophe.NS.PUBSUB+"#errors");
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
import BrowserStorage from "backbone.browserStorage"; import BrowserStorage from "backbone.browserStorage";
import converse from "@converse/headless/converse-core"; import converse from "@converse/headless/converse-core";
const { Backbone, Promise, Strophe, $iq, $pres, dayjs, sizzle, _ } = converse.env; const { Backbone, Strophe, $iq, $pres, dayjs, sizzle, _ } = converse.env;
const u = converse.env.utils; const u = converse.env.utils;
......
...@@ -10,7 +10,7 @@ import BrowserStorage from "backbone.browserStorage"; ...@@ -10,7 +10,7 @@ import BrowserStorage from "backbone.browserStorage";
import converse from "./converse-core"; import converse from "./converse-core";
import tpl_vcard from "./templates/vcard.html"; import tpl_vcard from "./templates/vcard.html";
const { Backbone, Promise, Strophe, _, $iq, $build, dayjs, sizzle } = converse.env; const { Backbone, Strophe, _, $iq, $build, dayjs, sizzle } = converse.env;
const u = converse.env.utils; const u = converse.env.utils;
......
...@@ -6,40 +6,12 @@ ...@@ -6,40 +6,12 @@
// Copyright (c) 2013-2017, Jan-Carel Brand <jc@opkode.com> // Copyright (c) 2013-2017, Jan-Carel Brand <jc@opkode.com>
// Licensed under the Mozilla Public License (MPLv2) // Licensed under the Mozilla Public License (MPLv2)
// //
import 'dayjs/locale/af'; import * as strophe from 'strophe.js/src/core';
import 'dayjs/locale/ar';
import 'dayjs/locale/bg';
import 'dayjs/locale/ca';
import 'dayjs/locale/cs';
import 'dayjs/locale/de';
import 'dayjs/locale/eo';
import 'dayjs/locale/es';
import 'dayjs/locale/eu';
import 'dayjs/locale/fr';
import 'dayjs/locale/gl';
import 'dayjs/locale/he';
import 'dayjs/locale/hi';
import 'dayjs/locale/hu';
import 'dayjs/locale/id';
import 'dayjs/locale/it';
import 'dayjs/locale/ja';
import 'dayjs/locale/nb';
import 'dayjs/locale/nl';
import 'dayjs/locale/oc-lnc';
import 'dayjs/locale/pl';
import 'dayjs/locale/pt';
import 'dayjs/locale/pt-br';
import 'dayjs/locale/ro';
import 'dayjs/locale/ru';
import 'dayjs/locale/tr';
import 'dayjs/locale/uk';
import 'dayjs/locale/zh-cn';
import 'dayjs/locale/zh-tw';
import Jed from "jed"; import Jed from "jed";
import Promise from "es6-promise/dist/es6-promise.auto";
import _ from "./lodash.noconflict";
import dayjs from "dayjs"; import dayjs from "dayjs";
const Strophe = strophe.default.Strophe;
function detectLocale (library_check) { function detectLocale (library_check) {
/* Determine which locale is supported by the user's system as well /* Determine which locale is supported by the user's system as well
...@@ -69,11 +41,11 @@ function detectLocale (library_check) { ...@@ -69,11 +41,11 @@ function detectLocale (library_check) {
} }
function isConverseLocale (locale, supported_locales) { function isConverseLocale (locale, supported_locales) {
return _.isString(locale) && _.includes(supported_locales, locale); return typeof locale === 'string' && supported_locales.includes(locale);
} }
function getLocale (preferred_locale, isSupportedByLibrary) { function getLocale (preferred_locale, isSupportedByLibrary) {
if (_.isString(preferred_locale)) { if (typeof preferred_locale === 'string') {
if (preferred_locale === 'en' || isSupportedByLibrary(preferred_locale)) { if (preferred_locale === 'en' || isSupportedByLibrary(preferred_locale)) {
return preferred_locale; return preferred_locale;
} }
...@@ -103,12 +75,8 @@ let jed_instance; ...@@ -103,12 +75,8 @@ let jed_instance;
*/ */
export default { export default {
setLocales (preferred_locale, _converse) { getLocale (preferred_locale, available_locales) {
_converse.locale = getLocale( return getLocale(preferred_locale, preferred => isConverseLocale(preferred, available_locales));
preferred_locale,
_.partial(isConverseLocale, _, _converse.locales)
);
dayjs.locale(getLocale(preferred_locale, l => dayjs.locale(l)));
}, },
translate (str) { translate (str) {
...@@ -127,14 +95,16 @@ export default { ...@@ -127,14 +95,16 @@ export default {
* Fetch the translations for the given local at the given URL. * Fetch the translations for the given local at the given URL.
* @private * @private
* @method i18n#fetchTranslations * @method i18n#fetchTranslations
* @param { String } locale -The given i18n locale * @param { _converse }
* @param { Array } supported_locales - List of locales supported
*/ */
async fetchTranslations (locale, supported_locales) { async fetchTranslations (_converse) {
if (!isConverseLocale(locale, supported_locales) || locale === 'en') { const locale = _converse.locale;
if (!isConverseLocale(locale, _converse.locales) || locale === 'en') {
return; return;
} }
const { default: data } = await import(/*webpackChunkName: "locales/[request]" */ `../../locale/${locale}/LC_MESSAGES/converse.po`); const { default: data } = await import(/*webpackChunkName: "locales/[request]" */ `../../locale/${locale}/LC_MESSAGES/converse.po`);
await import(/*webpackChunkName: "locales/dayjs/[request]" */ `dayjs/locale/${locale.toLowerCase().replace('_', '-')}`);
dayjs.locale(getLocale(_converse.locale, l => dayjs.locale(l)));
jed_instance = new Jed(data); jed_instance = new Jed(data);
} }
}; };
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
"devDependencies": { "devDependencies": {
"backbone": "1.4", "backbone": "1.4",
"backbone.browserStorage": "0.0.5", "backbone.browserStorage": "0.0.5",
"es6-promise": "^4.2.8",
"filesize": "^4.1.2", "filesize": "^4.1.2",
"jed": "1.1.1", "jed": "1.1.1",
"lodash": "^4.17.14", "lodash": "^4.17.14",
......
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