rubenv/angular-gettext-tools — pull request #36 by astotzer (2014-09-15 14:16:23+00:00)
Title: Make catalog name and catalog accessor function name customizable

Hi,

the project I am currently working for requires the gettext catalog name and accessor function name to be customizable through configuration parameters in order to avoid coupling to the API of angular-gettext. What we like to do is something like this:

Grunt Config:

nggettext_extract: {
pot: {
options: {
markerName: 'translate',
catalogMarkerName: 'i18nService',
catalogAccessorName: 'getTranslation',
catalogAccessorPluralName: 'getPluralTranslation'
},
files: {
'po/template.pot': ['src/app/**/*.html', 'src/app/**/*.js']
}
}
},
nggettext_compile: {
all: {
options: {
module: 'app',
catalogMarkerName: 'i18nService',
catalogAccessorName: 'setTranslations'
},
files: {
'src/app/translations.js': ['po/*.po']
}
}
}

AngularJS Code:

angular.module("myApp").controller("helloController", function (i18nService) {
var myString = i18nService.getTranslation("Hello");
var myString2 = i18nService.getPluralTranslation(3, "Bird", "Birds");
});

In order to get access to the translated strings in AngularJS we will create a wrapper around angular-gettext which simply forwards the calls to gettextCatalog.getString, gettextCatalog.getPlural, ...
Using this approach we are completely independent from the angular-gettext API and can even interchange our internationalisation provider if the need arises.

Thanks for checking my modifications and for your feedback!

Cheers Andi