webapp/src/utils/translate.ts
2022-09-09 14:53:35 +03:00

16 lines
416 B
TypeScript

import translate from 'google-translate-api-x'
import type { Shout } from '../graphql/types.gen'
export const translateHook = (aaa, locale) => {
if (aaa?.length > 0) {
console.log('[zine] articles loaded')
if (locale !== 'ru') {
// translate titles
aaa.forEach((a: Shout) =>
translate(a.title, { to: locale.get() }).then((res) => (a.title = res.text))
)
}
}
return aaa
}