(attributes)
| 509 | // - Internationalization |
| 510 | |
| 511 | updateI18NCoverage (attributes) { |
| 512 | const langCodeArrays = [] |
| 513 | const pathToData = {} |
| 514 | if (attributes == null) { |
| 515 | ({ |
| 516 | attributes, |
| 517 | } = this) |
| 518 | } |
| 519 | |
| 520 | // TODO: Share this code between server and client |
| 521 | // NOTE: If you edit this, edit the server side version as well! |
| 522 | TreemaUtils.walk(attributes, this.schema(), null, function (path, data, workingSchema) { |
| 523 | // Store parent data for the next block... |
| 524 | let prop |
| 525 | if (data != null ? data.i18n : undefined) { |
| 526 | pathToData[path] = data |
| 527 | } |
| 528 | |
| 529 | if (_.string.endsWith(path, 'i18n')) { |
| 530 | const i18n = data |
| 531 | |
| 532 | // grab the parent data |
| 533 | const parentPath = path.slice(0, -5) |
| 534 | const parentData = pathToData[parentPath] |
| 535 | |
| 536 | // use it to determine what properties actually need to be translated |
| 537 | let props = workingSchema.props || [] |
| 538 | props = ((() => { |
| 539 | const result = [] |
| 540 | for (prop of Array.from(props)) { |
| 541 | if (parentData[prop] && !['sound', 'soundTriggers'].includes(prop)) { |
| 542 | result.push(prop) |
| 543 | } |
| 544 | } |
| 545 | return result |
| 546 | })()) |
| 547 | if (!props.length) { return } |
| 548 | if ('additionalProperties' in i18n) { return } // Workaround for #2630: Programmable is weird |
| 549 | |
| 550 | // get a list of lang codes where its object has keys for every prop to be translated |
| 551 | const coverage = _.filter(_.keys(i18n), function (langCode) { |
| 552 | const translations = i18n[langCode] |
| 553 | return translations && _.all(((() => { |
| 554 | const result1 = [] |
| 555 | for (prop of Array.from(props)) { |
| 556 | result1.push(translations[prop]) |
| 557 | } |
| 558 | return result1 |
| 559 | })())) |
| 560 | }) |
| 561 | // console.log 'got coverage', coverage, 'for', path, props, workingSchema, parentData |
| 562 | return langCodeArrays.push(coverage) |
| 563 | } |
| 564 | }) |
| 565 | |
| 566 | if (!langCodeArrays.length) { return } |
| 567 | // language codes that are covered for every i18n object are fully covered |
| 568 | const overallCoverage = _.intersection(...Array.from(langCodeArrays || [])) |
no test coverage detected