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 @@
"es6-promise": {
"version": "4.2.8",
"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": {
"version": "5.0.0",
......
......@@ -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 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;
......
......@@ -17,7 +17,7 @@ import tpl_controlbox_toggle from "templates/controlbox_toggle.html";
import tpl_login_panel from "templates/login_panel.html";
const CHATBOX_TYPE = 'chatbox';
const { Strophe, Backbone, Promise, _, dayjs } = converse.env;
const { Strophe, Backbone, _, dayjs } = converse.env;
const u = converse.env.utils;
const CONNECTION_STATUS_CSS_CLASS = {
......
......@@ -16,7 +16,7 @@ import tpl_toggle_chats from "templates/toggle_chats.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;
converse.plugins.add('converse-minimize', {
......
......@@ -43,7 +43,7 @@ import tpl_spinner from "templates/spinner.html";
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 ROLES = ['moderator', 'participant', 'visitor'];
......
......@@ -13,7 +13,7 @@ import BrowserStorage from "backbone.browserStorage";
import converse from "@converse/headless/converse-core";
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;
Strophe.addNamespace('OMEMO_DEVICELIST', Strophe.NS.OMEMO+".devicelist");
......
......@@ -18,8 +18,7 @@ import tpl_profile_modal from "templates/profile_modal.html";
import tpl_profile_view from "templates/profile_view.html";
import tpl_status_option from "templates/status_option.html";
const { Strophe, Backbone, Promise, utils, _, dayjs, sizzle } = converse.env;
const { Strophe, Backbone, utils, _, dayjs, sizzle } = converse.env;
const u = converse.env.utils;
......
......@@ -16,7 +16,7 @@ import muc from "@converse/headless/converse-muc";
import tpl_rooms_list from "templates/rooms_list.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;
......
......@@ -13,7 +13,7 @@ import "@converse/headless/converse-muc";
import BrowserStorage from "backbone.browserStorage";
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;
......
......@@ -12,7 +12,7 @@ import BrowserStorage from "backbone.browserStorage";
import converse from "./converse-core";
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;
Strophe.addNamespace('MESSAGE_CORRECT', 'urn:xmpp:message-correct:0');
......
......@@ -11,7 +11,6 @@ import 'strophe.js/src/websocket';
import * as strophe from 'strophe.js/src/core';
import Backbone from 'backbone';
import BrowserStorage from 'backbone.browserStorage';
import Promise from 'es6-promise/dist/es6-promise.auto';
import _ from './lodash.noconflict';
import advancedFormat from 'dayjs/plugin/advancedFormat';
import dayjs from 'dayjs';
......@@ -832,10 +831,15 @@ _converse.initialize = async function (settings, callback) {
});
/* Localisation */
if (i18n !== undefined) {
i18n.setLocales(settings.i18n, _converse);
} else {
if (i18n === undefined || _converse.isTestEnv()) {
_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
......@@ -1331,18 +1335,12 @@ _converse.initialize = async function (settings, callback) {
this.connection = settings.connection;
}
await finishInitialization();
if (_converse.isTestEnv()) {
await finishInitialization();
return _converse;
} else if (i18n !== undefined) {
try {
await i18n.fetchTranslations(_converse.locale, _converse.locales);
} catch (e) {
_converse.log(e.message, Strophe.LogLevel.FATAL);
}
} else {
return init_promise;
}
await finishInitialization();
return init_promise;
};
/**
......
......@@ -12,7 +12,7 @@ import BrowserStorage from "backbone.browserStorage";
import converse from "./converse-core";
import sizzle from "sizzle";
const { Backbone, Promise, Strophe, $iq, utils, _ } = converse.env;
const { Backbone, Strophe, $iq, utils, _ } = converse.env;
converse.plugins.add('converse-disco', {
......
......@@ -23,7 +23,7 @@ const MUC_ROLE_WEIGHTS = {
'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
Strophe.addNamespace('MUC_ADMIN', Strophe.NS.MUC + "#admin");
......
......@@ -9,7 +9,7 @@
import "./converse-disco";
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");
......
......@@ -9,7 +9,7 @@
import BrowserStorage from "backbone.browserStorage";
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;
......
......@@ -10,7 +10,7 @@ import BrowserStorage from "backbone.browserStorage";
import converse from "./converse-core";
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;
......
......@@ -6,40 +6,12 @@
// Copyright (c) 2013-2017, Jan-Carel Brand <jc@opkode.com>
// Licensed under the Mozilla Public License (MPLv2)
//
import 'dayjs/locale/af';
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 * as strophe from 'strophe.js/src/core';
import Jed from "jed";
import Promise from "es6-promise/dist/es6-promise.auto";
import _ from "./lodash.noconflict";
import dayjs from "dayjs";
const Strophe = strophe.default.Strophe;
function detectLocale (library_check) {
/* Determine which locale is supported by the user's system as well
......@@ -69,11 +41,11 @@ function detectLocale (library_check) {
}
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) {
if (_.isString(preferred_locale)) {
if (typeof preferred_locale === 'string') {
if (preferred_locale === 'en' || isSupportedByLibrary(preferred_locale)) {
return preferred_locale;
}
......@@ -103,12 +75,8 @@ let jed_instance;
*/
export default {
setLocales (preferred_locale, _converse) {
_converse.locale = getLocale(
preferred_locale,
_.partial(isConverseLocale, _, _converse.locales)
);
dayjs.locale(getLocale(preferred_locale, l => dayjs.locale(l)));
getLocale (preferred_locale, available_locales) {
return getLocale(preferred_locale, preferred => isConverseLocale(preferred, available_locales));
},
translate (str) {
......@@ -127,14 +95,16 @@ export default {
* Fetch the translations for the given local at the given URL.
* @private
* @method i18n#fetchTranslations
* @param { String } locale -The given i18n locale
* @param { Array } supported_locales - List of locales supported
* @param { _converse }
*/
async fetchTranslations (locale, supported_locales) {
if (!isConverseLocale(locale, supported_locales) || locale === 'en') {
async fetchTranslations (_converse) {
const locale = _converse.locale;
if (!isConverseLocale(locale, _converse.locales) || locale === 'en') {
return;
}
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);
}
};
......@@ -24,7 +24,6 @@
"devDependencies": {
"backbone": "1.4",
"backbone.browserStorage": "0.0.5",
"es6-promise": "^4.2.8",
"filesize": "^4.1.2",
"jed": "1.1.1",
"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