I'm trying to use Jed for translating an angular app. For this, I use an Angular service providing the Jed object. Now, Jed already needs the translations, which are stored in a JSON file, when it is created:
jed = new Jed( jsonData );
alert( jed.gettext( 'I am translated!' ) );
So, with an Ajax request,
app.factory( 'jed', function ( $http ) {
var ret = { jed: null };
$http.get( 'i18n/de_CH/messages.json' )
.success( function ( data ) {
ret.jed = new Jed( data );
} );
return {
get jed() {
// Is null until we receive messages.json
return ret.jed;
}
};
} );
Problem is that jed is not initialised until the HTTP request returns.
Possible solution is to return a deferred object, but then usage is ugly as we always have to check the deferred object and use function callbacks, and also inlined {{jed.gettext( 'Quit' )}} does not work anymore.
Is there a clean way of doing this?