debian-mirror-gitlab/app/assets/javascripts/language_switcher/index.js
2023-03-04 22:38:38 +05:30

23 lines
709 B
JavaScript

import Vue from 'vue';
import { getCookie } from '~/lib/utils/common_utils';
import LanguageSwitcher from './components/app.vue';
import { PREFERRED_LANGUAGE_COOKIE_KEY } from './constants';
export const initLanguageSwitcher = () => {
const el = document.querySelector('.js-language-switcher');
if (!el) return false;
const locales = JSON.parse(el.dataset.locales);
const preferredLangCode = getCookie(PREFERRED_LANGUAGE_COOKIE_KEY);
const preferredLocale = locales.find((locale) => locale.value === preferredLangCode);
return new Vue({
el,
provide: {
locales,
preferredLocale,
},
render(createElement) {
return createElement(LanguageSwitcher);
},
});
};