logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://anongit.hacktivis.me/git/pleroma-fe.git/

service_worker_messages.js (903B)


  1. import { languages, langCodeToJsonName } from '../src/i18n/languages.js'
  2. import { readFile } from 'node:fs/promises'
  3. import { dirname, resolve } from 'node:path'
  4. import { fileURLToPath } from 'node:url'
  5. const i18nDir = resolve(
  6. dirname(dirname(fileURLToPath(import.meta.url))),
  7. 'src/i18n'
  8. )
  9. export const i18nFiles = languages.reduce((acc, lang) => {
  10. const name = langCodeToJsonName(lang)
  11. const file = resolve(i18nDir, name + '.json')
  12. acc[lang] = file
  13. return acc
  14. }, {})
  15. export const generateServiceWorkerMessages = async () => {
  16. const msgArray = await Promise.all(Object.entries(i18nFiles).map(async ([lang, file]) => {
  17. const fileContent = await readFile(file, 'utf-8')
  18. const msg = {
  19. notifications: JSON.parse(fileContent).notifications || {}
  20. }
  21. return [lang, msg]
  22. }))
  23. return msgArray.reduce((acc, [lang, msg]) => {
  24. acc[lang] = msg
  25. return acc
  26. }, {})
  27. }