All Downloads are FREE. Search and download functionalities are using the official Maven repository.

public.js.common.localization.localization_loader.js Maven / Gradle / Ivy

There is a newer version: 1.1.0
Show newest version
(function LocalizationLoader(){
    const DEFAULT_LOCALE = "hu";

    window.localizationLoader = new function(){
        this.loadLocalization = loadLocalization
    }

    function loadLocalization(fileName, successCallback){
        const request = new Request(HttpMethod.GET, getPath(localeService.getLocale(), fileName));
            request.convertResponse = function(response){
                return JSON.parse(response.body);
            }
            request.processValidResponse = function(localization){
                successCallback(localization);
            }
            request.processInvalidResponse = function(){
                createFallBackQuery(fileName, successCallback);
            }
        dao.sendRequestAsync(request);

        function createFallBackQuery(fileName, successCallback){
            const request = new Request(HttpMethod.GET, getPath(DEFAULT_LOCALE, fileName));
                request.convertResponse = function(response){
                    return JSON.parse(response.body);
                }
                request.processValidResponse = function(localization){
                    successCallback(localization);
                }
            dao.sendRequestAsync(request);
        }

        function getPath(locale, fileName){
            return "/i18n/" + locale + "/" + fileName + ".json";
        }
    }
})();




© 2015 - 2024 Weber Informatics LLC | Privacy Policy