Fix updateI18NCoverage, handles i18n objects with nothing to translate, fix #2630

This commit is contained in:
Scott Erickson 2016-08-30 14:17:40 -07:00
parent be11c47e17
commit 652c5237aa
2 changed files with 39 additions and 17 deletions

View file

@ -416,11 +416,7 @@ class CocoModel extends Backbone.Model
# 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 unless props.length
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

View file

@ -151,23 +151,49 @@ describe 'CocoModel', ->
describe 'updateI18NCoverage', ->
class FlexibleClass extends CocoModel
@className: 'Flexible'
@schema: {}
@schema: {
type: 'object'
properties: {
name: { type: 'string' }
description: { type: 'string' }
innerObject: {
type: 'object'
properties: {
name: { type: 'string' }
i18n: { type: 'object', format: 'i18n', props: ['name']}
}
}
i18n: { type: 'object', format: 'i18n', props: ['description', 'name', 'prop1']}
}
}
it 'only includes languages for which all objects include a translation', ->
m = new FlexibleClass({
i18n: { es: {}, fr: {} }
prop1: 1
prop2: 'string'
prop3: true
i18n: { es: { name: '+', description: '+' }, fr: { name: '+', description: '+' } }
name: 'Name'
description: 'Description'
innerObject: {
i18n: { es: {}, de: {}, fr: {} }
prop4: [
{
i18n: { es: {} }
}
]
i18n: { es: { name: '+' }, de: { name: '+' }, fr: {} }
name: 'Name'
}
})
m.updateI18NCoverage()
expect(JSON.stringify(m.get('i18nCoverage'))).toBe('["es"]')
expect(_.isEqual(m.get('i18nCoverage'), ['es'])).toBe(true)
it 'ignores objects for which there is nothing to translate', ->
m = new FlexibleClass()
m.set({
name: 'Name'
i18n: {
'-': {'-':'-'}
'es': {name: 'Name in Spanish'}
}
innerObject: {
i18n: { '-': {'-':'-'} }
}
})
m.updateI18NCoverage()
expect(_.isEqual(m.get('i18nCoverage'), ['es'])).toBe(true)