-
Notifications
You must be signed in to change notification settings - Fork 827
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix GH 1102: Don’t allow duplicate strings in a single l10n file (#1150)
* Don’t allow duplicate strings in a single l10n file Added check_duplicate_strings to test for duplicates in a single file. removed duplicates - tried to keep the more generic ‘key’ * revised test case for safer file reads
- Loading branch information
1 parent
4c6522f
commit e1a0e9f
Showing
12 changed files
with
61 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Check that there are no duplicate strings in any individual l10n json file. | ||
*/ | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var tap = require('tap'); | ||
|
||
var routes = require('../../src/routes.json'); | ||
|
||
function noDuplicateValues (idsToCheck, name) { | ||
var values = {}; | ||
for (var key in idsToCheck) { | ||
if (values.hasOwnProperty(idsToCheck[key])) { | ||
// duplicate values | ||
//return false; | ||
tap.fail(name + '.' + idsToCheck[key] + ' has duplicates'); | ||
} else { | ||
values[idsToCheck[key]] = key; | ||
} | ||
} | ||
tap.pass(); | ||
//return true; | ||
} | ||
|
||
tap.test('generalCheckForDuplicates', function (t) { | ||
var ids = require(path.resolve(__dirname, '../../src/l10n.json')); | ||
noDuplicateValues(ids, 'general'); | ||
t.end(); | ||
}); | ||
|
||
for (var v in routes) { | ||
if (typeof routes[v].redirect !== 'undefined') { | ||
continue; | ||
} | ||
var subdir = routes[v].view.split('/'); | ||
subdir.pop(); | ||
var name = routes[v].name; | ||
var uri = path.resolve(__dirname, '../../src/views/' + subdir.join('/') +'/l10n.json'); | ||
try { | ||
var file = fs.readFileSync(uri, 'utf8'); | ||
var ids = JSON.parse(file); | ||
tap.test(name + 'CheckForDuplicates', function (t) { | ||
noDuplicateValues(ids, name); | ||
t.end(); | ||
}); | ||
} catch (err) { | ||
if (err.code !== 'ENOENT') { | ||
// ignore if ENOENT for routes with no l10n file, throw error for anything else | ||
throw err; | ||
} | ||
} | ||
} |