I have a Json file (rawResult) that contains few elements that needs to be updated.
Basically any element key in the json that contains "|translate", then the value part should be replaced with the text from the respective dictionary (Spanish or English).
var rawResult = "{"fields": [{
"fieldGroup": [
{
"key": "Task",
"type": "input",
"templateOptions": {
"label|translate": "task_templateoptions_label",
"placeholder|translate": "task_templateoptions_placeholder"
},
"validation": {
"messages": {
"required|translate": "task_validation_messages_required",
}
}
},
{
"key": "Sub Task",
"type": "input",
"templateOptions": {
"label|translate": "sub_task_templateOptions_label",
"placeholder|translate": "sub_task_templateOptions_placeholder"
}
}
]
}]}"
//Dictionary for Spanish
Dictionary<string, string> dcSpanish = new Dictionary<string, string>();
dcSpanish.Add("task_templateoptions_label", "Tarea");
dcSpanish.Add("task_templateoptions_placeholder", "Ingrese el nombre de la tarea");
dcSpanish.Add("task_validation_messages_required", "El nombre de la tarea es obligatorio");
dcSpanish.Add("sub_task_templateOptions_label", "Sub tarea");
dcSpanish.Add("sub_task_templateOptions_placeholder", "Ingrese el nombre de la subtarea");
//Dictionary for English
Dictionary<string, string> dcEnglish = new Dictionary<string, string>();
dcEnglish.Add("task_templateoptions_label", "Task");
dcEnglish.Add("task_templateoptions_placeholder", "Enter the task name");
dcEnglish.Add("task_validation_messages_required", "Task name is required");
dcEnglish.Add("sub_task_templateOptions_label", "Sub task");
dcEnglish.Add("sub_task_templateOptions_placeholder", "Enter the sub task name");
So in case the Json result is requested in Spanish, then the output should be,
var result = "{"fields": [{
"fieldGroup": [
{
"key": "Task",
"type": "input",
"templateOptions": {
"label": "Tarea",
"placeholder": "Ingrese el nombre de la tarea"
},
"validation": {
"messages": {
"required": "El nombre de la tarea es obligatorio",
}
}
},
{
"key": "Sub Task",
"type": "input",
"templateOptions": {
"label": "Sub tarea",
"placeholder": "Ingrese el nombre de la subtarea"
}
}
]
}]}"