intel / appframeworkPlugins

Plugins for jqMobi
17 stars 23 forks source link

i18n : Problen when no properties file for a language #7

Open skaldrom opened 11 years ago

skaldrom commented 11 years ago

The i18n plugin can use the browsers preferred language for selecting a properties file and should fallback to the "Messages.properties" file.

Usually, you cannot provide properties files for all the possible languages, so some requests to files will fail, because they do not exist.

Problem: the event "i18n:complete" only gets triggered in the "success" part of the ajax request. If some files fail, it won't be triggered and the callback is never called, because it waits for this event.

Solution: Add an "error" function to the ajax request on line 256:

    $.ajax({
        url:        filename,
        async:      true,
        cache:      settings.cache,
        contentType:'text/plain;charset='+ settings.encoding,
        dataType:   'text',
        success:    function(data, status) {
                        parseData(data, settings.mode); 
                        _parsedFiles++;;
                        if(_parsedFiles>=_filesToLoad){
                           $(document).trigger("i18n:complete");
                        }
                    },
        error:    function(XMLHttpRequest, textStatus, errorThrown) { 
                        _parsedFiles++;;
                        if(_parsedFiles>=_filesToLoad){
                           $(document).trigger("i18n:complete");
                        }
    }       
fpmweb commented 10 years ago

Great! thanks.