loadIntlMessages.js 518 B

1234567891011121314151617181920
  1. import fs from "fs/promises"
  2. import path from "path"
  3. export default async function loadI18nMessages({ locale, defaultLocale }) {
  4. // If the default locale is being used we can skip it
  5. if (locale === defaultLocale) {
  6. return {}
  7. }
  8. if (locale !== defaultLocale) {
  9. const languagePath = path.join(process.cwd(), `locales/${locale}.json`)
  10. try {
  11. const contents = await fs.readFile(languagePath, "utf-8")
  12. return JSON.parse(contents)
  13. } catch (error) {
  14. console.error(error)
  15. }
  16. }
  17. }