Last active
August 29, 2015 14:22
-
-
Save johndaley-me/4de3935c177b446cfb46 to your computer and use it in GitHub Desktop.
Lazy Load language files for angular-gettext
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
(function () { | |
// remove ng-app from body | |
function bootstrapApp() { | |
angular.element(document).ready(function () { | |
angular.bootstrap(document, ['myApp']); | |
}); | |
} | |
var key = window.localStorage.getItem('language'); | |
if (key && key !== 'en') { | |
$.ajax({ | |
url: 'languages/' + key + '.js', | |
dataType: 'script', | |
success: bootstrapApp, | |
cache: true // otherwise jQuery reloads this every time with a timestamped query parameter | |
}); | |
} else { | |
bootstrapApp(); | |
} | |
})(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is useful if your app is setup such that it has to completely reload after a language change. The app can window.localStorage.setItem('language', languageId); and then reload.