mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-13 22:49:51 -04:00
Made i18n coverage more strict about making sure every property that needs to be translated is translated.
This commit is contained in:
parent
b6de218fa1
commit
ffc33279b8
1 changed files with 30 additions and 15 deletions
|
@ -377,22 +377,37 @@ class CocoModel extends Backbone.Model
|
|||
#- Internationalization
|
||||
|
||||
updateI18NCoverage: ->
|
||||
i18nObjects = @findI18NObjects()
|
||||
return unless i18nObjects.length
|
||||
langCodeArrays = (_.keys(i18n) for i18n in i18nObjects)
|
||||
@set('i18nCoverage', _.intersection(langCodeArrays...))
|
||||
langCodeArrays = []
|
||||
pathToData = {}
|
||||
|
||||
findI18NObjects: (data, results) ->
|
||||
data ?= @attributes
|
||||
results ?= []
|
||||
TreemaUtils.walk(@attributes, @schema(), null, (path, data, workingSchema) ->
|
||||
# Store parent data for the next block...
|
||||
if data?.i18n
|
||||
pathToData[path] = data
|
||||
|
||||
if _.string.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])
|
||||
|
||||
# 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))
|
||||
)
|
||||
langCodeArrays.push coverage
|
||||
)
|
||||
|
||||
return unless langCodeArrays.length
|
||||
# language codes that are covered for every i18n object are fully covered
|
||||
overallCoverage = _.intersection(langCodeArrays...)
|
||||
@set('i18nCoverage', overallCoverage)
|
||||
|
||||
if _.isPlainObject(data) or _.isArray(data)
|
||||
for [key, value] in _.pairs data
|
||||
if key is 'i18n'
|
||||
results.push value
|
||||
else if _.isPlainObject(value) or _.isArray(value)
|
||||
@findI18NObjects(value, results)
|
||||
|
||||
return results
|
||||
|
||||
module.exports = CocoModel
|
||||
|
|
Loading…
Reference in a new issue