File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11<template >
22 <div id =" app" >
3+ <select class =" language-switch" v-model =" $i18n.locale" >
4+ <option v-for =" locale in displayLocales" :key =" `locale-${locale.value}`" :value =" locale.value" >
5+ {{ locale.name }}
6+ </option >
7+ </select >
8+
39 <div class =" head" >
410 <a href =" #" class =" logo" >
511 <img src =" ./assets/logo.png" alt =" asf logo" >
612 </a >
713 <h1 class =" text-center" v-html =" $t('app.name')" ></h1 >
814 </div >
15+
916 <div class =" menu" >
1017 <ul >
1118 <li ><router-link :to =" { name: 'home' }" active-class =" active" v-html =" $t('link.home')" exact ></router-link ></li >
2128<script >
2229 export default {
2330 name: ' app' ,
24- data () {
25- return {}
31+ computed: {
32+ availableLocales () {
33+ return this .$i18n .availableLocales .map ((locale ) => {
34+ return {
35+ value: locale,
36+ code: locale === ' strings' ? ' en-US' : locale
37+ }
38+ }).sort ((lhs , rhs ) => {
39+ return lhs .code .localeCompare (rhs .code )
40+ })
41+ },
42+ displayLocales () {
43+ return this .availableLocales .map ((locale ) => {
44+ if (' Intl' in window && ' DisplayNames' in Intl ) {
45+ const displayNamesTranslator = new Intl.DisplayNames ([locale .code ], { type: ' language' });
46+ return { value: locale .value , name: displayNamesTranslator .of (locale .code ) }
47+ }
48+
49+ return { value: locale .value , name: locale .code }
50+ })
51+ }
2652 }
2753 }
2854 </script >
84110 .logo {
85111 margin : 0 auto ;
86112 }
113+
114+ .language-switch {
115+ position : absolute ;
116+ top : 8px ;
117+ left : 8px ;
118+ width : 220px ;
119+ }
87120 </style >
You can’t perform that action at this time.
0 commit comments