mergeARBs function
Merges two ARB (Application Resource Bundle) files.
This function includes the novel keys of arb2Contents in the arb1Contents
and returns the result of the merge. In case of discrepancies of
the values for the same key, the arb2Contents will prevail.
In a nutshell arb1Contents <-merge-- arb2Contents
Parameters:
arb1Contents: The base ARB file contents as a JSON stringarb2Contents: The ARB file contents to merge into the base as a JSON string
Returns: Merged ARB file contents as a JSON string
Example:
final baseArb = '{"appName": "My App", "welcomeMessage": "Welcome!"}';
final newArb = '{"appName": "New App Name", "newFeature": "New Feature"}';
final merged = mergeARBs(baseArb, newArb);
// Result: '{"appName": "New App Name", "welcomeMessage": "Welcome!", "newFeature": "New Feature"}'
Implementation
String mergeARBs(String arb1Contents, String arb2Contents) {
Map<String, dynamic> ret = json.decode(arb1Contents);
Map<String, dynamic> json2 = json.decode(arb2Contents);
for (var key in json2.keys) {
ret[key] = json2[key];
}
return json.encode(ret);
}