Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// @flow
import Translate from '@google-cloud/translate'
import Project from '@models/Project'
import Locale from '@models/Locale'
import TranslationValue from '@models/TranslationValue'
const translate = new Translate({ key: process.env.TRANSLATE_API_KEY })
const prefillTranslationsValues = async (
project: Project,
newLocale: Locale
) => {
const defaultLocale = project.locales[0]
const sortedKeys = project.translationKeys.sort((a, b) => a.id - b.id)
const stringsToBeTranslated = sortedKeys.map(translationKey => {
const translationValue = translationKey.translationValues.find(
translationValue => translationValue.locale.code === defaultLocale.code
)
return translationValue ? translationValue.value : ''
})
const targetLanguage = newLocale.code