/* * Copyright @ 2015 Atlassian Pty Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var i18n = require("i18next-client"); var languages = require("../../service/translation/languages"); var Settings = require("../settings/Settings"); var DEFAULT_LANG = languages.EN; i18n.addPostProcessor("resolveAppName", function(value, key, options) { return value.replace("__app__", interfaceConfig.APP_NAME); }); var defaultOptions = { detectLngQS: "lang", useCookie: false, fallbackLng: DEFAULT_LANG, load: "unspecific", resGetPath: 'lang/__ns__-__lng__.json', ns: { namespaces: ['main', 'languages'], defaultNs: 'main' }, lngWhitelist : languages.getLanguages(), fallbackOnNull: true, fallbackOnEmpty: true, useDataAttrOptions: true, defaultValueFromContent: false, app: interfaceConfig.APP_NAME, getAsync: false, defaultValueFromContent: false, customLoad: function(lng, ns, options, done) { var resPath = "lang/__ns__-__lng__.json"; if(lng === languages.EN) resPath = "lang/__ns__.json"; var url = i18n.functions.applyReplacement(resPath, { lng: lng, ns: ns }); i18n.functions.ajax({ url: url, success: function(data, status, xhr) { i18n.functions.log('loaded: ' + url); done(null, data); }, error : function(xhr, status, error) { if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { // file loaded but invalid json, stop waste time ! i18n.functions.error('There is a typo in: ' + url); } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { i18n.functions.log('Does not exist: ' + url); } else { var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); i18n.functions.log(theStatus + ' when loading ' + url); } done(error, {}); }, dataType: "json", async : options.getAsync }); } // options for caching // useLocalStorage: true, // localStorageExpirationTime: 86400000 // in ms, default 1 week }; function initCompleted(t) { $("[data-i18n]").i18n(); } function checkForParameter() { var query = window.location.search.substring(1); var vars = query.split("&"); for (var i=0;i