mirror of
https://gitlab.com/prism-break/prism-break.git
synced 2025-04-24 09:08:29 +00:00
Output warnings about duplicate localizations
This commit is contained in:
parent
9fcac7b01b
commit
44cd350b2b
@ -4,10 +4,12 @@
|
||||
"description": "A directory of free privacy-oriented software.",
|
||||
"main": "Makefile",
|
||||
"dependencies": {
|
||||
"es7-array.prototype.includes": "^2.0.0",
|
||||
"graceful-fs": "~4.1.4",
|
||||
"jade": "~1.11.0",
|
||||
"livescript": "~1.5.0",
|
||||
"lodash.assign": "^4.2.0",
|
||||
"lodash.isequal": "^4.4.0",
|
||||
"marked": "~0.3.5",
|
||||
"mkdirp": "~0.5.x",
|
||||
"moment": "^2.17.1",
|
||||
|
@ -1,6 +1,13 @@
|
||||
'use strict'
|
||||
|
||||
assign = require 'lodash.assign'
|
||||
isequal = require 'lodash.isequal'
|
||||
if not Array.prototype.includes then require 'es7-array.prototype.includes'
|
||||
|
||||
# TODO: support overrides
|
||||
# Then we can expand this list to include e.g. wikipedia_url, but not warn in situations where there isn't a translated Wikipedia article
|
||||
# When we do this we should warn about the presence of non-translatable keys (e.g. the `protocols` key should always be consistent)
|
||||
translatable = ['notes', 'description']
|
||||
|
||||
module.exports = load-data = (path, iso, find-missing = false) ->
|
||||
en-data = require path.replace('/' + iso, '/en')
|
||||
@ -14,8 +21,26 @@ module.exports = load-data = (path, iso, find-missing = false) ->
|
||||
potential-localized-obj = assign {}, obj, localized-obj
|
||||
break
|
||||
|
||||
if find-missing and not potential-localized-obj
|
||||
console.log 'Missing ' + iso + ' localization for ' + obj.name
|
||||
continue
|
||||
if find-missing
|
||||
if not potential-localized-obj
|
||||
console.log 'Missing ' + iso + ' localization for ' + obj.name
|
||||
continue
|
||||
else
|
||||
# First we check if entire objects are duplicated
|
||||
# We use localized-obj because potential-localized-obj has already been filled in by lodash.assign
|
||||
if isequal obj, localized-obj
|
||||
console.log iso + ' localization of ' + obj.name + ' duplicates the English version'
|
||||
# Then we check for per-key problems
|
||||
else
|
||||
# For each (non-empty) localizable key in the English version...
|
||||
for key of obj when translatable.includes key and obj[key] is not ''
|
||||
# ...check if it hasn't been localized at all
|
||||
if not localized-obj[key]
|
||||
console.log 'Missing ' + iso + ' localization for key `' + key + '` in project ' + obj.name
|
||||
# ...check if the localized version is a duplicate
|
||||
else if isequal obj[key], localized-obj[key]
|
||||
console.log iso + ' localization of key `' + key + '` in project ' + obj.name + ' duplicates the English version'
|
||||
|
||||
continue
|
||||
|
||||
potential-localized-obj or obj
|
||||
|
Loading…
x
Reference in New Issue
Block a user