debian-mirror-gitlab/app/assets/javascripts/language_switcher/index.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

24 lines
709 B
JavaScript
Raw Normal View History

2023-03-04 22:38:38 +05:30
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);
},
});
};