Search code examples
angularjslocalizationtranslateangular-translate

How to provide a fallback static file for angular-translate?


I'm using translateUrlLoader to bring the resource file from the server. In case this fails, i want to use a local file. how can i achieve that?


Solution

  • So I figured out a hack to resolve this. This is the code that I used to do:

    $translateProvider.translations('default', ResourceConstants.EnglishLabels).fallbackLanguage('default');
    

    So basically what this did was take a JSON and use it for populating the translation table in case selected language is 'default'. And then I provide 'default' as the fallback language (name is irrelevant). This is then used in case your get request (ajax)

    $translateProvider.useUrlLoader('requestPath')
    

    fails.