Skip to main content

Diff

Compare at least two i18n files and generate a report

Command

# Display help for diff
npx @jy95/i18n-tools diff --help

Purpose

Suppose you have several versions of a i18n locale file such as :

fr_v0.json
{
"untouchedKey":"Hello World",
"commons":{
"nestedKey":{
"changedValue":"Changed value 0"
},
"array":[
"Pierre"
],
"conditionalDeletedKey":"Present"
}
}

This command generates a report (in JSON by default) that shows change(s) between files :

fr_v0-fr_v0.json
{
"files": {
"file1":"D:\\TEMP\\fr_v0.json",
"file2":"D:\\TEMP\\fr_v0.json"
},
"changes": []
}

Examples of settings

npx @jy95/i18n-tools diff --settings "/absolutePath/to/settings1.json"
settings1.json
{
"filename":"diff_settings1-JSON",
"outputDir":"D:\\TEMP\\TEMP",
"outputFormat":"JSON",
"files":[
"D:\\TEMP\\fr_v0.json",
"D:\\TEMP\\fr_v1.json"
]
}

FAQ

The files I use are flat JSON. How can I make this command work ?

Simply set option keySeparator to false in your settings.json or settings.js, such as :

settings.json
{
"keySeparator": false
}
I only want some types of changes reported in the result file. How can I achieve that ?

Simply set the operations option in your settings.json or settings.js to your liking :

tip

Current operations are :

OperationDescription
PUTWhen key exists in both file1 & file2 but value was replaced
ADDWhen key exists in file2 but not in file1
DELWhen key exists in file1 but not in file2
settings.json
{
"operations": ["PUT"]
}