• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zooniverse / front-end-monorepo / 16353963243

17 Jul 2025 07:15PM UTC coverage: 79.486% (+1.6%) from 77.896%
16353963243

Pull #6877

github

web-flow
Merge 64dce5980 into 1609d4670
Pull Request #6877: build(deps): bump the babel group with 8 updates

11179 of 15980 branches covered (69.96%)

Branch coverage included in aggregate %.

17448 of 20035 relevant lines covered (87.09%)

399.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.78
/packages/app-project/src/helpers/fetchTranslations/fetchTranslations.js
1
import { panoptes } from '@zooniverse/panoptes-js'
1✔
2
import { mergeWith } from 'lodash'
1✔
3

4
import getServerSideAPIHost from '@helpers/getServerSideAPIHost'
1✔
5
import logToSentry from '@helpers/logger/logToSentry.js'
368✔
6

7
export default async function fetchTranslations({
203!
8
  translated_id,
37✔
9
  translated_type,
10
  fallback = 'en',
37✔
11
  language,
12
  env
13
}) {
14
  const lowerCaseLang = language?.toLowerCase() // zh-CN and zh-TW are stored as lowercase in panoptes
37✔
15
  const { headers, host } = getServerSideAPIHost(env)
16
  const languages = language === fallback ? fallback : `${lowerCaseLang},${fallback}`
37✔
17
  const query = {
37✔
18
    language: languages,
19
    translated_id,
20
    translated_type,
21
    env
22
  }
37✔
23
  if (translated_id) {
74✔
24
    try {
25
      const response = await panoptes.get('/translations', query, { ...headers }, host)
36✔
26

27
      const translation = response.body.translations.find(t => t.language === lowerCaseLang)
38✔
28
      const original = response.body.translations.find(t => t.language === fallback)
36✔
29

30
      if (!translation || !Object.keys(translation.strings).length) {
38✔
31
        return original
32
      }
33

34
      /* If a project team leaves part of a language untranslated, backfill it with the strings from the fallback language */
35
      const customizer = (objValue, srcValue) => objValue === "" ? srcValue : objValue
19!
36

37
      const mergedStrings = mergeWith(translation.strings, original.strings, customizer)
19✔
38
      return Object.assign(translation, {strings: mergedStrings})
×
39
        } catch (error) {
40
      console.error(error)
×
41
      logToSentry(error, { query, host })
1✔
42
    }
43
  }
44
  return null
×
45
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc