{"size": 1238, "ext": "js", "max_stars_repo_path": "lib/i18n.js", "max_stars_repo_name": "Coxibiz/geo.data.gouv.fr", "max_stars_repo_stars_event_min_datetime": "2017-10-15T13:43:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-24T02:06:05.000Z", "max_issues_repo_path": "lib/i18n.js", "max_issues_repo_name": "Coxibiz/geo.data.gouv.fr", "max_issues_repo_issues_event_min_datetime": "2017-10-12T10:03:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-10T16:19:47.000Z", "max_forks_repo_path": "lib/i18n.js", "max_forks_repo_name": "sgmap-inspire/inspire.data.gouv.fr", "max_forks_repo_forks_event_min_datetime": "2018-04-12T15:16:12.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-15T08:49:49.000Z"}
{"max_stars_count": 65, "max_issues_count": 513, "max_forks_count": 12, "avg_line_length": 21.3448275862, "max_line_length": 73, "alphanum_fraction": 0.5807754443}
import i18n from 'i18next'
import XHR from 'i18next-xhr-backend'
import moment from 'moment'

const dev = process.env.NODE_ENV !== 'production'

export const languages = [
  'fr',
  'en'
]

if (!i18n.isInitialized) {
  // eslint-disable-next-line import/no-named-as-default-member
  i18n
    .use(XHR)
    .init({
      fallbackLng: 'fr',
      load: 'languageOnly',
      lowerCaseLng: true,

      ns: ['common'],
      defaultNS: 'common',
      whitelist: [...languages],

      saveMissing: dev,

      interpolation: {
        escapeValue: false,
        formatSeparator: ',',
        format: (value, format) => {
          if (format === 'uppercase') {
            return value.toUpperCase()
          }

          return value
        }
      },

      backend: {
        loadPath: '/locales/{{lng}}/{{ns}}.json',
        addPath: '/locales/add/{{lng}}/{{ns}}'
      }
    })

  // eslint-disable-next-line import/no-named-as-default-member
  i18n.on('languageChanged', () => {
    const [language] = i18n.languages

    moment.locale(language)

    // Next.js doesn’t support changing <html /> properties with <Head />
    // So we’re setting it manually.
    document.documentElement.lang = language
  })
}

export default i18n
