Dynamic messages with gettext (AngularJS) - django

I have a application with a Django backend and an AngularJS front-end.
I use the angular-gettext plugin along with Grunt to handle translations.
The thing is, I sometimes received dynamic strings from my backend through the API. For instance a MySQL error about a foreign key constraint or duplicate key entry.
How can I add this strings to the .pot file or non harcoded string in general ?
I've tried to following but of course it cannot work :
angular.module('app').factory('HttpInterceptor', ['$q', '$injector', '$rootScope', '$cookieStore', 'gettext', function ($q, $injector, $rootScope, $cookieStore, gettext) {
responseError: function (rejection) {
gettext('static string'); //it works
gettext(rejection.data.error); //does not work
$rootScope.$emit('errorModal', rejection.data);
}
// Return the promise rejection.
return $q.reject(rejection);
}
};
}]);
})();
One solution I could think of would be to write every dynamic strings into a JSON object. Send this json to server and from there, write a static file containing these strings so gettext can extract them.
What do you suggest ?

I also use angular-gettext and have strings returned from the server that need to be translated. We did not like the idea of having a separate translation system for those messages so we send them over in the default language like normal.
To allow this to work we did two things. We created a function in our backend which we can call to retrieve all the possible strings to translate. In our case it's mainly static data that only changes once in a while. Ideally this would be automated but it's fine for now.
That list is formatted properly through code into html with the translate tag. This file is not deployed, it is just there to allow the extraction task to find the strings.
Secondly we created a filter to do the translation on the interpolated value, so instead of translating {{foo}} it will translate the word bar if that's was the value of foo. We called this postTranslate and it's a simple:
angular
.module('app')
.filter('postTranslate', ['gettextCatalog', function (gettextCatalog) {
return function (s) {
return gettextCatalog.getString(s);
};
}]);
As for things that are not in the database we have another file for those where we manually put them in. So your error messages may go here.
If errors are all you are worried about though, you may rather consider not showing all the error messages directly and instead determine what user friendly error message to show. That user friendly error message is in the front end and therefore circumvents all of this other headache :)

Related

Apollo iOS how to handle partial decoding failure

I'm trying to see if there is a way to do more robust handling of partial decoding failures of Apollo generated Swift classes. Currently, if even one field of one object in an array fails to parse from the network response, the entire collection of objects fails to parse and our iOS client gets no data.
Our graphql is defined something like:
query mobile_getCollections() {
getCollections() {
// ... other fields
items {
activeRange {
expires // Int!
starts // Int!
}
}
}
}
So the Apollo generated Swift code is expecting non-nil Ints when decoding these values. However, due to a backend error (that we would like to make the mobile clients more resilient to), the API will occasionally send us a malformed date String instead of a unix timestamp Int. This causes parsing of the entire mobile_getCollections result to fail, because the Apollo generated query class typing can't be perfectly satisfied.
Ideally, I'd like to just throw out the one item in the collection that failed to be parsed correctly and leave the remaining items intact. Is it possible to do something like that using Apollo?
(Yes, I know the real answer here is to fix the backend, but is there anything I can do in the mean time to more gracefully handle similar partial parsing failure issues?)

How to change input soap request as per test data in loadrunner?

I am working with one soap request where we need to pass,single data in one parameter and in 2nd iteration we need to pass multiple test data in same input request.Please help me how to change input soap request as per test data,please find below soap requests for single and multiple requests.
Single Request:
<ReqDtls>
<vReqs>
<amount>1.00</amount>
<cardNo>8897654778999</cardNo>
</Reqs>
<cardType>caredit</cardType>
</ReqDtls>
Multiple Requests:In same soap input requests,it is changing dynamically from POS system but i want to perform in loadrunner.
<ReqDtls>
<vReqs>
<amount>1.00</amount>
<cardNo>8897654778999</cardNo>
</Reqs>
<vReqs>
<amount>2.00</amount>
<cardNo>890897654778999</cardNo>
</Reqs>
<cardType>caredit</cardType>
</ReqDtls>
Any code in vugen to pass this type of values from excel file for loadtesting,please help how to do this one
This is where you will use your foundation skills in programming as well as a web_custom_request() (Potentially) to send your own custom string.
Notice the repeated piece here
<vReqs>
<amount>{amount_variable}</amount>
<cardNo>{card_variable}</cardNo>
</Reqs>
You have a defined header
<ReqDtls>
And a defined footer
<cardType>caredit</cardType>
</ReqDtls>
This now becomes a matter of string concatenation in C and turning the variables into literals. Consider a loop and lowly sprintf() for this task. Note, variable declarations are not included in the code fragment
sprintf(mybigstring,"<ReqDtls>\r");
for (myloopcounter=1;myloopcounter<=mylooplimit;myloopcounter++)
{
sprintf(mybigstring,
"%s%s",
mybigstring,
lr_eval_string("<vReqs>\r<amount>{amount_variable}</amount>\r<cardNo>{card_variable}</cardNo>\r</Reqs>\r") );
lr_advance_param("amount_variable");
lr_advance_param("card_variable");
}
sprintf(mybigstring,"%s%s",mybigstring,"<cardType>caredit</cardType>\r</ReqDtls>");
The above is directly from noggin to screen so it may require a bit if fiddling, but it should give you an idea for a path.
Once you have your string, then you can use it in whatever request as needed.

Intercepting error handling with loopback

Is there somewhere complete, consistent and well documented source of information on error handling in loopback?
Things like error codes and their meaning, relation with http statuses. I've already read their docs and have not found anything like this.
I would like to translate all the messages to add multi language support to my app. I would also like to add my custom messages, with their code and to use it consistently with other loopback errors.
In order to achieve this, I need to intercept all the errors (I've done this already) and to know all the possible different codes, so I can translate them.
For example, if there is an error with code 555, I have to know what it means and treat it accordingly.
Any ideas?
I need to "catch" all the messages and translate them
This is the beginning of an answer. You can write an error-handling middleware that will intercept any error returned by the server. You will need in turn to implement the logic for making the translation.
module.exports = function() {
return function logError(err, req, res, next) {
if (err) {
console.log('ERR', req.url, err);
}
next();
};
};
This middleware must be configured to be called in the final phase. Save the code above in log-error.js for instance, then modify server/middleware.json
{ "final": { "./middleware/log-error": {} } }
I need a full list of loopback codes/messages
I'm pretty sure there is no such thing. Errors are build and returned all over the place in the code, not centralized anywhere.

Ember.js - What purpose does Ember.lookup serve

Can anyone tell me what purpose Ember.lookup serves?
It is used to lookup string keys.
An example of its use in the ember source is:
if(typeof modelType === "string"){
return Ember.get(Ember.lookup, modelType);
} else {
return modelType;
}
I can see that it returns a type from a string but I don't see where it is set or what the bigger picture is for its usage.
Ember.lookup was introduced along with Ember.imports and Ember.exports as a way to remove the dependency on window.
If you are running Ember in the browser, all three values will refer to the window, however if you are running without the browser, for instance, through NodeJS or with AMD, you will need to supply values yourself.
See the commit message for more information.

Retrieve service information from WFS GetCapabilities request with GeoExt

This is probably a very simple question but I just can't seem to figure it out.
I am writing a Javascript app to retrieve layer information from a WFS server using a GetCapabilities request using GeoExt. GetCapabilities returns information about the WFS server -- the server's name, who runs it, etc., in addition to information on the data layers it has on offer.
My basic code looks like this:
var store = new GeoExt.data.WFSCapabilitiesStore({ url: serverURL });
store.on('load', successFunction);
store.on('exception', failureFunction);
store.load();
This works as expected, and when the loading completes, successFunction is called.
successFunction looks like this:
successFunction = function(dataProxy, records, options) {
doSomeStuff();
}
dataProxy is a Ext.data.DataProxy object, records is a list of records, one for each layer on the WFS server, and options is empty.
And here is where I'm stuck: In this function, I can get access to all the layer information regarding data offered by the server. But I also want to extract the server information that is contained in the XML fetched during the store.load() (see below). But I can't figure out how to get it out of the dataProxy object, where I'm sure it must be squirreled away.
Any ideas?
The fields I want are contained in this snippet:
<ows:ServiceIdentification>
<ows:Title>G_WIS_testIvago</ows:Title>
<ows:Abstract/>
<ows:Keywords>
<ows:Keyword/>
</ows:Keywords>
<ows:ServiceType>WFS</ows:ServiceType>
<ows:ServiceTypeVersion>1.1.0</ows:ServiceTypeVersion>
<ows:Fees/>
<ows:AccessConstraints/>
Apparently,GeoExt currently discards the server information, undermining the entire premise of my question.
Here is a code snippet that can be used to tell GeoExt to grab it. I did not write this code, but have tested it, and found it works well for me:
https://github.com/opengeo/gxp/blob/master/src/script/plugins/WMSSource.js#L37