Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mohantechnology committed Mar 19, 2022
1 parent 4493d80 commit 1f68203
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
22 changes: 13 additions & 9 deletions dashboard/public/js/l10n.js
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ document.webL10n = (function(window, document, undefined) {
*/

// load the default locale on startup
function l10nStartup() {
function l10nStartup(lang,callback) {
gReadyState = 'interactive';

// most browsers expose the UI language as `navigator.language'
Expand All @@ -1006,21 +1006,24 @@ document.webL10n = (function(window, document, undefined) {

// load the default locale and translate the document if required
if (document.documentElement.lang === userLocale) {
loadLocale(userLocale);
loadLocale(userLocale,callback);
} else {
loadLocale(userLocale, translateFragment);
loadLocale(lang,callback);
// loadLocale("hi", translateFragment);
}
}

// browser-specific startup
// start 'L10nStartup' with language and callback after page fully loaded
function startL10nStartup(lang,callback){
// browser-specific startup
if (document.addEventListener) { // modern browsers and IE9+
if (document.readyState === 'loading') {
// the document is not fully loaded yet: wait for DOMContentLoaded.
document.addEventListener('DOMContentLoaded', l10nStartup);
document.addEventListener('DOMContentLoaded', ()=>l10nStartup( lang ,callback));
} else {
// l10n.js is being loaded with <script defer> or <script async>,
// the DOM is ready for parsing.
window.setTimeout(l10nStartup);
window.setTimeout(()=>l10nStartup( lang ,callback));
}
} else if (window.attachEvent) { // IE8 and before (= oldIE)
// TODO: check if jQuery is loaded (CSS selector + JSON + events)
Expand Down Expand Up @@ -1125,9 +1128,10 @@ document.webL10n = (function(window, document, undefined) {
// startup for IE<9
window.attachEvent('onload', function() {
gTextProp = document.textContent === null ? 'textContent' : 'innerText';
l10nStartup();
l10nStartup(lang ,callback);
});
}
}

// cross-browser API (sorry, oldIE doesn't support getters & setters)
return {
Expand Down Expand Up @@ -1157,8 +1161,8 @@ document.webL10n = (function(window, document, undefined) {

// get|set the document language
getLanguage: function() { return gLanguage; },
setLanguage: function(lang, callback) {
loadLocale(lang, function() {
setLanguage: function(lang, callback) {
startL10nStartup(lang, function() {
if (callback)
callback();
translateFragment();
Expand Down
4 changes: 2 additions & 2 deletions dashboard/public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,8 @@ function onLocalized() {
};
}
}
document.webL10n.ready(onLocalized);

// document.webL10n.ready(onLocalized);
onLocalized() ; // call this function to start localization
// Initiate localization in mobile view
$(document).ready(function() {
var toggle = document.getElementById('navbar-toggle');
Expand Down

0 comments on commit 1f68203

Please sign in to comment.