Created
June 8, 2016 01:10
-
-
Save headquarters/dc50efb943e871595e419cfce5eb8477 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Diff Java resource bundles to find missing keys. | |
| */ | |
| var fs = require('fs'); | |
| var englishFile = 'path/to/ResourceBundleMessage.properties'; | |
| var germanFile = 'path/to/ResourceBundleMessage_de.properties'; | |
| var japaneseFile = 'path/to/ResourceBundleMessage_ja.properties'; | |
| var chineseFile = 'path/to/ResourceBundleMessage_zh_CN.properties'; | |
| var englishKeysAndValues = {}; | |
| var germanKeysAndValues = {}; | |
| var japaneseKeysAndValues = {}; | |
| var chineseKeysAndValues = {}; | |
| var englishKeys = null; | |
| var missingKeys = ''; | |
| var totalMissingKeys = 0; | |
| var putFileContentsIntoObject = function(fileContents, object){ | |
| //split up the lines | |
| var fileString = fileContents.toString(); | |
| var linesArray = fileString.split('\n'); | |
| var linesLength = linesArray.length; | |
| for(var i = 0; i < linesLength; i++){ | |
| var currentLineArray = linesArray[i].split('=', 2); | |
| var trimmedKey = currentLineArray[0] ? currentLineArray[0].trim() : ''; | |
| var trimmedValue = currentLineArray[1] ? currentLineArray[1].trim() : ''; | |
| object[trimmedKey] = trimmedValue; | |
| } | |
| } | |
| //grab file contents *synchronously* from the various files | |
| var fileContents = fs.readFileSync(englishFile); | |
| putFileContentsIntoObject(fileContents, englishKeysAndValues); | |
| var fileContents = fs.readFileSync(germanFile); | |
| putFileContentsIntoObject(fileContents, germanKeysAndValues); | |
| var fileContents = fs.readFileSync(japaneseFile); | |
| putFileContentsIntoObject(fileContents, japaneseKeysAndValues); | |
| var fileContents = fs.readFileSync(chineseFile); | |
| putFileContentsIntoObject(fileContents, chineseKeysAndValues); | |
| //go through each of the English keys and find any that are missing from the other files | |
| for(var key in englishKeysAndValues){ | |
| //missingKeys += 'Missing German Keys \r\n'; | |
| if(typeof germanKeysAndValues[key] === 'undefined'){ | |
| missingKeys += 'Missing ' + key + ' from ResourceBundleMessage_de.properties. English version is "' + englishKeysAndValues[key] + '".\r\n'; | |
| totalMissingKeys++; | |
| } | |
| //missingKeys += 'Missing Japanese Keys \r\n'; | |
| if(typeof japaneseKeysAndValues[key] === 'undefined'){ | |
| missingKeys += 'Missing ' + key + ' from ResourceBundleMessage_ja.properties. English version is "' + englishKeysAndValues[key] + '".\r\n'; | |
| totalMissingKeys++; | |
| } | |
| //missingKeys += 'Missing Chinese Keys \r\n'; | |
| if(typeof chineseKeysAndValues[key] === 'undefined'){ | |
| missingKeys += 'Missing ' + key + ' from ResourceBundleMessage_zh_CN.properties. English version is "' + englishKeysAndValues[key] + '".\r\n'; | |
| totalMissingKeys++; | |
| } | |
| } | |
| fs.writeFileSync('results.txt', missingKeys); | |
| console.log('File results.txt written. Total missing keys: ' + totalMissingKeys); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment