MCPcopy Index your code
hub / github.com/codecombat/codecombat / populateI18N

Method populateI18N

app/models/CocoModel.js:420–462  ·  view source on GitHub ↗
(data, schema, path)

Source from the content-addressed store, hash-verified

418 }
419
420 populateI18N (data, schema, path) {
421 // TODO: Better schema/json walking
422 let value
423 if (path == null) { path = '' }
424 let sum = 0
425 if (data == null) { data = $.extend(true, {}, this.attributes) }
426 if (schema == null) { schema = this.schema() || {} }
427 if (schema.oneOf) { // get populating the Programmable component config to work
428 schema = _.find(schema.oneOf, { type: 'object' }) || schema
429 }
430 let addedI18N = false
431 if ((schema.properties != null ? schema.properties.i18n : undefined) && _.isPlainObject(data) && (data.i18n == null)) {
432 data.i18n = { '-': { '-': '-' } } // mongoose doesn't work with empty objects
433 sum += 1
434 addedI18N = true
435 }
436
437 if (_.isPlainObject(data)) {
438 for (const key in data) {
439 value = data[key]
440 let numChanged = 0
441 let childSchema = schema.properties != null ? schema.properties[key] : undefined
442 if (!childSchema && _.isObject(schema.additionalProperties)) {
443 childSchema = schema.additionalProperties
444 }
445 if (childSchema) {
446 numChanged = this.populateI18N(value, childSchema, path + '/' + key)
447 }
448 if (numChanged && !path) { // should only do this for the root object
449 this.set(key, value)
450 }
451 sum += numChanged
452 }
453 }
454
455 if (schema.items && _.isArray(data)) {
456 for (let index = 0; index < data.length; index++) { value = data[index]; sum += this.populateI18N(value, schema.items, path + '/' + index) }
457 }
458
459 if (addedI18N && !path) { this.set('i18n', data.i18n) } // need special case for root i18n
460 if (!path) { this.updateI18NCoverage() } // only need to do this at the highest level
461 return sum
462 }
463
464 setURL (url) {
465 const makeURLFunc = u => () => u

Callers 13

onPopulateI18NMethod · 0.80
onPopulateI18NMethod · 0.80
onPopulateI18NMethod · 0.80
onPopulateI18NMethod · 0.80
onPopulateI18NMethod · 0.80
onPopulateI18NMethod · 0.80
onPopulateI18NMethod · 0.80
onPopulateI18NMethod · 0.80
onPopulateLevelI18NMethod · 0.80
onPopulateI18NMethod · 0.80
onPopulateI18NMethod · 0.80
onPopulateI18NMethod · 0.80

Calls 3

schemaMethod · 0.95
setMethod · 0.95
updateI18NCoverageMethod · 0.95

Tested by

no test coverage detected