<commit_before>import i18n from '@/i18n'
import axios from 'axios'
import dateFnsHelper from '@/services/dateFnsHelper'
import polyfill from '@/polyfill'
import { messages as loadMessages, quasarMessages as loadQuasarMessages } from '@/locales'
import Quasar from 'quasar-vue-plugin'

export default store => {
  store.watch(state => state.i18n.locale, async locale => {
    const [messages, { default: quasarMessages }] = await Promise.all([
      loadMessages(locale),
      loadQuasarMessages(locale),
    ])
    i18n.setLocaleMessage(locale, messages)

    // Prevent race condition when updating locales quickly
    // If the locale changed while loading messages from the server, don't continue
    if (store.state.i18n.locale !== locale) return

    i18n.locale = locale
    dateFnsHelper.locale = locale
    polyfill.locale = locale
    Quasar.i18n.set(quasarMessages)
    axios.defaults.headers.common['Accept-Language'] = locale
    document.documentElement.setAttribute('lang', locale)
  }, { immediate: true })
}
<commit_msg>debounce loading locales<commit_after>import i18n from '@/i18n'
import axios from 'axios'
import dateFnsHelper from '@/services/dateFnsHelper'
import polyfill from '@/polyfill'
import { messages as loadMessages, quasarMessages as loadQuasarMessages } from '@/locales'
import Quasar from 'quasar-vue-plugin'
import { debounce } from 'quasar'

export default store => {
  const loadLocale = debounce(async locale => {
    axios.defaults.headers.common['Accept-Language'] = locale
    document.documentElement.setAttribute('lang', locale)
    dateFnsHelper.locale = locale
    polyfill.locale = locale

    const [messages, { default: quasarMessages }] = await Promise.all([
      loadMessages(locale),
      loadQuasarMessages(locale),
    ])
    i18n.setLocaleMessage(locale, messages)

    // Prevent race condition when updating locales quickly
    // If the locale changed while loading messages from the server, don't continue
    if (store.state.i18n.locale !== locale) return

    i18n.locale = locale
    Quasar.i18n.set(quasarMessages)
  }, 100)
  store.watch(state => state.i18n.locale, loadLocale, { immediate: true })
}

{'fraction_non_alphanumeric': 0.10613751730503, 'fraction_numerical': 0.01430549146285187, 'mean_word_length': 4.174224343675418, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7216959', 'n_tokens_mistral': 670, 'n_tokens_neox': 640, 'n_words': 174}