// Converse.js (A browser based XMPP chat client) // http://conversejs.org // // This is the internationalization module. // // Copyright (c) 2012-2017, Jan-Carel Brand // Licensed under the Mozilla Public License (MPLv2) // /*global define */ (function (root, factory) { define([ "es6-promise", "jed", "lodash.noconflict", "moment", 'moment/locale/af', 'moment/locale/ca', 'moment/locale/de', 'moment/locale/es', 'moment/locale/fr', 'moment/locale/he', 'moment/locale/hu', 'moment/locale/id', 'moment/locale/it', 'moment/locale/ja', 'moment/locale/nb', 'moment/locale/nl', 'moment/locale/pl', 'moment/locale/pt-br', 'moment/locale/ru', 'moment/locale/uk', 'moment/locale/zh-cn', 'moment/locale/zh-tw' ], factory); }(this, function (Promise, Jed, _, moment) { 'use strict'; function detectLocale (library_check) { /* Determine which locale is supported by the user's system as well * as by the relevant library (e.g. converse.js or moment.js). * * Parameters: * (Function) library_check - Returns a boolean indicating whether * the locale is supported. */ var locale, i; if (window.navigator.userLanguage) { locale = isLocaleAvailable(window.navigator.userLanguage, library_check); } if (window.navigator.languages && !locale) { for (i=0; i1) { return t.fetch.apply(t, [].slice.call(arguments, 1)); } else { return t.fetch(); } }, fetchTranslations (locale, supported_locales, locale_url) { /* Fetch the translations for the given local at the given URL. * * Parameters: * (String) locale: The given i18n locale * (Array) supported_locales: List of locales supported * (String) locale_url: The URL from which the translations * should be fetched. */ return new Promise((resolve, reject) => { if (!isConverseLocale(locale, supported_locales) || locale === 'en') { return resolve(); } const xhr = new XMLHttpRequest(); xhr.open('GET', locale_url, true); xhr.setRequestHeader( 'Accept', "application/json, text/javascript" ); xhr.onload = function () { if (xhr.status >= 200 && xhr.status < 400) { jed_instance = new Jed(window.JSON.parse(xhr.responseText)); resolve(); } else { xhr.onerror(); } }; xhr.onerror = function () { reject(xhr.statusText); }; xhr.send(); }); } }; }));