Is it possible to write default values for translations? - i18next

json
"success":"Congratulations: you have bought {{type}}"
js
return (<span>{t('success', {type: 'oranges'}))</span>)
Is it possible to write a default value into the json? Something like this:
json
"success":"Congratulations: you have bought {{type || apples}}"
js
return (<span>{t('success'))</span>)
I haven't spotted anything in the documentation.

Related

ORDS: Removing escaping char from json in ORDS OUT param

I am using the OUT parameter in the ORDS parameters to send a response which is already in JSON and this stored as CLOB in the DB. When I send this out in the response from the ORDS, ORDS is actually adding lot of back spaces to the response.
Can someone help me to understand how I can remove the escaping chars here(all the backslashes). I had tried a different approach explained by Jeff in another thread to try to use an alias for the JSON key, but it did not work for me.
Over here I have mentioned the response as OUT parameter in my code.
eg payload:
{
"response": "{\n\"Order\":{\n\"OriginalShipmentID\":1\n,\"orderNumber\":1\n,\"orgID\":1\n,\"orderShipmentNumber\":1\n,\"oracleShipSet\":\"1\"\n,\"OeHeaderId\":1\n,\"GsHeaderId\":1\n,\"CustomerPoNumber\":\"1\"\n,\"PaymentTerms\":1\n,\"FreightTerms\":\"PAID\"\n,\"CurrencyCode\":\"USD\"\n,\"BillToSiteUseID\":1\n,\"ShipToSiteUseID\":1\n,\"SalesChannel\":\"DIRECT\"\n,\"HeaderKeyCode\":\"1 1\"\n,\"OrigSysDocumentRef\":\"1\"\n,\"OrderTypeCode\":\"XYZ yXYZ\"\n,\"OrderTypeID\":1\n,\"SalesRepID\":-3\n,\"IsAtgOrder\":\"N\"\n,\"OrderSource\":\"MCP\"\n,\"OdiDocSet\":\"PO\"\n,\"CsServiceSymbol\":\"XYZ\"\n,\"CsServiceFriendlyName\":\"XYZ\"\n,\"CsShipper\":\"NDC_MX\"\n,\"GsShipToAddressID\":1\n,\"GsBillFrtAddressID\":-1\n,\"BillingMethod\":\"DoNotBillFreight\"\n,\"ReasonForNoInvoice\":\"NA\"\n,\"ShippedBy\":\"NA\"\n,\"ManifestID\":1771748\n,\"IsVoided\":\"N\"\n,\"CustomerNumber\":\"1\"\n,\"OrderLines\":[\n]\n,\"HeaderShortNotes\":{\n}\n}\n}\n"
}
Some more details:
SELECT get_json ( :ordernumber,
:warehouseid,
:shipset,
:ordershipmentno,
:gsshipmentid,
:countrycode,
:shipperid,
:fromcurrency,
:tocurrency,
:groupid,
:optionvalues,
:linehaul,
:servicename,
:sigid,
:lineid,
:customerid) "{}Order"
INTO l_response_clob
FROM DUAL;
This function returns a CLOB with a JSON format data and l_response_clob is defined as STRING output parameter on the ORDS.
Essentially, I want to stop ORDS from again converting JSON to JSON.
Been banging head over this from some time but can't seem to make it work.
Thanks for the help I can get here.

Value of json has multiple data-types (json-shema)

I have a question about json-schema on karatedsl..
For example i have a json, and one of the key of the json have multiple data-type (for example, it could be #string or #object)
How to validate json that have multiple data-type on karatedsl ??
Example #string :
{
"customer_id":"081234562002",
"order_id":"",
"amount":20700,
"price":20700,
"created":1560684244,
"changed":1560684246,
"data":"Internal Server Error"
}
Example #object :
{
"customer_id":"081234562002",
"order_id":"",
"amount":20700,
"price":20700,
"created":1560684244,
"changed":1560684246,
"data":
{"message": "Internal Server Error"}
}
And i have separated json file for validate the json above, like this :
{
"customer_id":"#string",
"order_id":"#string",
"amount":"#number",
"price":"#number",
"created":"#number",
"changed":"#number",
"data":"???"
}
There are multiple options in karate to do this, i can give one quick example here,
* match response.myKey == "#? karate.match(_,'#string').pass || karate.match(_,'#object').pass"
since we need markers like #string i have to use karate.match. you can write any function that return boolean and use it here as a substitute.
read fuzzy matching, Self validation expression , Schema Validation from karate docs
Edit: for updated question
replace your ??? as
"#? karate.match(_,'Internal Server Error').pass || karate.match(_,{'message' :'Internal Server Error'} ).pass"

Best Postgres/DB format for storing an array of strings with a boolean attached to them in Django?

I'm storing an array of URL links in my Postgres database like this:
urls = ArrayField(
models.CharField(max_length=250, blank=False)
)
But I want to track if a URL has been visited or not, as a boolean. What is the best way to do this?
You can use django.contrib.postgres.fields.JSONField which can store data as JSON and is PostgreSQL specific field. So you can put in it dict with url and visited keys in it.
from django.core.serializers.json import DjangoJSONEncoder
...
urls = JSONField(encoder=DjangoJSONEncoder, default=dict)
https://docs.djangoproject.com/en/2.0/ref/contrib/postgres/fields/#django.contrib.postgres.fields.JSONField

m.request: use URL which contains colons

I have a m.request call like this:
mCmdName = "cn:cmd:list:deselectAll";
m.request({
method : "POST",
url : "/testing/cmd/" + mCmdName,
data: data
});
Now m.request calls
xhrOptions.url = parameterizeUrl(xhrOptions.url, xhrOptions.data);
and tries to replace all ':[name]' parts with data[name] which results in 'undefined' as data doesn't contain any of the keys. Data is just the data object of the XHR request.
Is there a way to prohibit this default behavior?
Thanks, Stefan
PS: I'm asking here and not in mithril mailing list because I can't post there for incomprehensible reasons. Maybe somebody can give me a hint on this.
Have you tried
encodeURIComponent("cn:cmd:list:deselectAll")
which gives you
cn%3Acmd%3Alist%3AdeselectAll
If necessary you can decode on the server.

Reading data from a CSVStore in Dojo

Let's say I have a CSVStore connected to an editable grid:
var csvStore = dojox.data.CsvStore({data: csvData, separator: ","});
this._grid = new dojox.grid.EnhancedGrid({
id: gridId,
store: csvStore,
structure: layout,
...
});
How can I retrieve the modified data stored in the CSVStore in CSV format? I'm looking for something like this:
var modifiedCSVData = csvStore.getCSVData();
I answered a similar question the other day. Someone was trying to get the data from a dojo store. In this case it was in JSON, not CSV. You could use the same technique to build an object. Then instead of converting it to JSON, convert it to CSV using Array.join as you said in your comment. Glad I could help, and I totally agree; this is a missing use case of the dojo store.