mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-30 19:06:59 -05:00
300c81e72b
* Restrict patch handling properly * Fix #3860, CS 2 description * i18nCoverage is updated when new translations are auto-accepted * Course patches are listed on PendingPatchesView properly * 'Artisan' permission allows editing course translations
43 lines
1.8 KiB
CoffeeScript
43 lines
1.8 KiB
CoffeeScript
TreemaUtils = require '../../bower_components/treema/treema-utils.js'
|
|
|
|
exports.updateI18NCoverage = (doc) ->
|
|
# TODO: Share this code between server and client (client version in CocoModel)
|
|
langCodeArrays = []
|
|
pathToData = {}
|
|
|
|
# console.log 'doc schema', doc.schema.statics.jsonSchema, doc.schema
|
|
TreemaUtils.walk(doc.toObject(), doc.schema.statics.jsonSchema, null, (path, data, workingSchema) ->
|
|
# Store parent data for the next block...
|
|
if data?.i18n
|
|
pathToData[path] = data
|
|
|
|
if _.str.endsWith path, 'i18n'
|
|
i18n = data
|
|
|
|
# grab the parent data
|
|
parentPath = path[0...-5]
|
|
parentData = pathToData[parentPath]
|
|
|
|
# use it to determine what properties actually need to be translated
|
|
props = workingSchema.props or []
|
|
props = (prop for prop in props when parentData[prop])
|
|
#unless props.length
|
|
# console.log 'props is', props, 'path is', path, 'data is', data, 'parentData is', parentData, 'workingSchema is', workingSchema
|
|
# langCodeArrays.push _.without _.keys(locale), 'update' # Every language has covered a path with no properties to be translated.
|
|
# return
|
|
|
|
return if 'additionalProperties' of i18n # Workaround for #2630: Programmable is weird
|
|
|
|
# get a list of lang codes where its object has keys for every prop to be translated
|
|
coverage = _.filter(_.keys(i18n), (langCode) ->
|
|
translations = i18n[langCode]
|
|
_.all((translations[prop] for prop in props))
|
|
)
|
|
#console.log 'got coverage', coverage, 'for', path, props, workingSchema, parentData
|
|
langCodeArrays.push coverage
|
|
)
|
|
|
|
return unless langCodeArrays.length
|
|
# language codes that are covered for every i18n object are fully covered
|
|
overallCoverage = _.intersection(langCodeArrays...)
|
|
doc.set('i18nCoverage', overallCoverage)
|