forked from swiftlang/swift-docc-render
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLocaleSelector.vue
86 lines (76 loc) · 1.94 KB
/
LocaleSelector.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<!--
This source file is part of the Swift.org open source project
Copyright (c) 2023 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception
See https://swift.org/LICENSE.txt for license information
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
-->
<template>
<div class="locale-selector">
<select
:value="$i18n.locale"
:aria-label="$t('select-language')"
@change="updateRouter"
>
<option
v-for="{ slug, name, code } in locales"
:key="slug"
:value="slug"
:lang="code"
>
{{ name }}
</option>
</select>
<ChevronThickIcon class="icon-inline" />
</div>
</template>
<script>
import ChevronThickIcon from 'theme/components/Icons/ChevronThickIcon.vue';
import appLocales from 'theme/lang/locales.json';
import { updateLocale, getLocaleParam } from 'docc-render/utils/i18n-utils';
import AppStore from 'docc-render/stores/AppStore';
export default {
name: 'LocaleSelector',
components: {
ChevronThickIcon,
},
methods: {
updateRouter({ target: { value: slug } }) {
this.$router.push(getLocaleParam(slug));
AppStore.setPreferredLocale(slug);
updateLocale(slug, this);
},
},
computed: {
availableLocales: () => AppStore.state.availableLocales,
locales: ({ availableLocales }) => (
appLocales.filter(({ code }) => availableLocales.includes(code))
),
},
};
</script>
<style scoped lang="scss">
@import 'docc-render/styles/_core.scss';
select {
@include font-styles(locale-selector);
color: var(--color-fill-blue);
padding-right: 15px;
appearance: none;
background: transparent;
border: none;
cursor: pointer;
&:hover {
@include underline-text;
}
}
.locale-selector {
position: relative;
}
.svg-icon.icon-inline {
position: absolute;
fill: var(--color-fill-blue);
right: 2px;
bottom: 7px;
height: 5px;
}
</style>