From f6d0941ee640e2480717b58247b175d1eb423ac0 Mon Sep 17 00:00:00 2001 From: Joao Ribeiro Date: Wed, 3 Aug 2016 18:21:49 +0100 Subject: [PATCH] Added option to load language files in a synchronous way --- src/jquery.i18n.messagestore.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/jquery.i18n.messagestore.js b/src/jquery.i18n.messagestore.js index 05fcb80..cfb0990 100644 --- a/src/jquery.i18n.messagestore.js +++ b/src/jquery.i18n.messagestore.js @@ -18,7 +18,8 @@ var MessageStore = function () { this.messages = {}; this.sources = {}; - }; + }, + sync = false; /** * See https://github.com/wikimedia/jquery.i18n/wiki/Specification#wiki-Message_File_Loading @@ -111,13 +112,17 @@ function jsonMessageLoader( url ) { var deferred = $.Deferred(); - $.getJSON( url ) - .done( deferred.resolve ) - .fail( function ( jqxhr, settings, exception ) { - $.i18n.log( 'Error in loading messages from ' + url + ' Exception: ' + exception ); - // Ignore 404 exception, because we are handling fallabacks explicitly - deferred.resolve(); - } ); + $.ajax( { + url: url, + dataType: 'json', + async: !sync + } ) + .done( deferred.resolve ) + .fail( function ( jqxhr, settings, exception ) { + $.i18n.log( 'Error in loading messages from ' + url + ' Exception: ' + exception ); + // Ignore 404 exception, because we are handling fallabacks explicitly + deferred.resolve(); + } ); return deferred.promise(); }