|
1 | 1 | <script setup lang="ts"> |
2 | | -import { onBeforeMount, onMounted, ref } from 'vue'; |
| 2 | +import { onBeforeMount, ref } from 'vue'; |
3 | 3 | import logo from '@geniale/assets/media/logo_flag2.svg'; |
| 4 | +import i18n from '@geniale/plugins/i18n'; |
| 5 | +import { faEarthAmerica } from '@fortawesome/free-solid-svg-icons'; |
| 6 | +import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'; |
4 | 7 |
|
5 | 8 | const isOpen = ref(false); |
6 | 9 |
|
@@ -33,23 +36,44 @@ onBeforeMount(() => { |
33 | 36 | } |
34 | 37 | }); |
35 | 38 |
|
36 | | -onMounted(() => { |
37 | | - if (window.location.pathname === '/dashboard') { |
38 | | - const navbar = document.getElementById('navbar'); |
39 | | - if (navbar) { |
40 | | - navbar.classList.remove('bg-white'); |
41 | | - navbar.classList.add('hidden'); |
| 39 | +const languages = [ |
| 40 | + { |
| 41 | + name: 'EN', |
| 42 | + code: 'en', |
| 43 | + }, |
| 44 | + { |
| 45 | + name: 'FR', |
| 46 | + code: 'fr', |
| 47 | + }, |
| 48 | +]; |
| 49 | +
|
| 50 | +let langIndex = languages.findIndex( |
| 51 | + lang => lang.code === i18n.global.locale.value |
| 52 | +); |
| 53 | +
|
| 54 | +// Hide navbar until scroll |
| 55 | +onBeforeMount(() => { |
| 56 | + // Check which page we are on |
| 57 | + for (const item of navbarItems) { |
| 58 | + if (window.location.pathname === item.link) { |
| 59 | + item.selected = true; |
42 | 60 | } |
43 | 61 | } |
44 | 62 | }); |
45 | 63 |
|
46 | 64 | // Set locale on select change |
47 | | -const onLocaleChange = (event: Event) => { |
48 | | - window.localStorage.setItem( |
49 | | - 'locale', |
50 | | - (event.target as HTMLSelectElement).value |
51 | | - ); |
| 65 | +const onLocaleChange = () => { |
| 66 | + langIndex = (langIndex + 1) % languages.length; |
| 67 | + changeLanguage(languages[langIndex].code); |
52 | 68 | }; |
| 69 | +
|
| 70 | +/** |
| 71 | + * |
| 72 | + */ |
| 73 | +function changeLanguage(newLang: string) { |
| 74 | + window.localStorage.setItem('locale', newLang); |
| 75 | + i18n.global.locale.value = newLang as typeof i18n.global.locale.value; |
| 76 | +} |
53 | 77 | </script> |
54 | 78 |
|
55 | 79 | <template> |
@@ -93,16 +117,16 @@ const onLocaleChange = (event: Event) => { |
93 | 117 | > |
94 | 118 | {{ $t(item.name) }} |
95 | 119 | </a> |
96 | | - <select |
97 | | - v-model="$i18n.locale" |
| 120 | + |
| 121 | + <button |
98 | 122 | :aria-label="$t('language')" |
99 | 123 | type="button" |
100 | | - class="text-gray-500 hover:text-primary-700 focus:text-gray-600 focus:outline-none pr-2 border-none" |
101 | | - @change="onLocaleChange" |
| 124 | + class="block md:inline-block px-2 py-1 text-white hover:text-gray-500 md:px-4 md:py-2 md:text-lg" |
| 125 | + @click="onLocaleChange" |
102 | 126 | > |
103 | | - <option value="en">EN</option> |
104 | | - <option value="fr">FR</option> |
105 | | - </select> |
| 127 | + <FontAwesomeIcon :icon="faEarthAmerica" class="w-6" /> |
| 128 | + {{ languages[langIndex].name }} |
| 129 | + </button> |
106 | 130 | </div> |
107 | 131 | </div> |
108 | 132 | </div> |
|
0 commit comments