mercy mercy - 1 year ago 102
AngularJS Question

angularjs $translate : get default translation in error handler

I have written this factory which will be called in case of any errors

app.factory('customTranslationHandler', function ($translate) {
return function (caption, uses) {
if(uses=='en') {
var i = 0, strLength = caption.length;
for(i; i < strLength; i++) {
caption = caption.replace("_", " ");
var defaultText = caption.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
} else {
//var defaultText = $translate(caption).use('en');
//var defaultText = $translate.instant(caption).use('en');

return defaultText;

If it is en, I format the caption and return it.
In case of any other language, I want to call translate for that caption using
as language. I get my translations from json files.

Answer Source

All I had to do was set fallBackLanguage:


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download