availableLocales.ts 725 B

12345678910111213141516171819202122
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { QueryHandler } from '#shared/server/apollo/handler/index.ts'
  3. import { useLocalesLazyQuery } from '#shared/graphql/queries/locales.api.ts'
  4. import type { LocalesQuery } from '#shared/graphql/types.ts'
  5. let availableLocales: Maybe<LocalesQuery['locales']>
  6. const getAvailableLocales = async (): Promise<
  7. Maybe<LocalesQuery['locales']>
  8. > => {
  9. if (availableLocales !== undefined) return availableLocales
  10. const query = new QueryHandler(useLocalesLazyQuery({ onlyActive: true }))
  11. const { data: result } = await query.query()
  12. availableLocales = result?.locales || null
  13. return availableLocales
  14. }
  15. export default getAvailableLocales