Skip to content

Commit

Permalink
adds french i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
Carsten König committed Aug 1, 2024
1 parent 1af88bf commit cb2ff0d
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 1.0.11

* update chinese translation, thanks @XiangtingLee, fixes [#251](https://github.com/cars10/elasticvue/pull/251)
* adds french translation, thanks @XNxa, fixes [#250](https://github.com/cars10/elasticvue/pull/250)

## 1.0.10

Expand Down
8 changes: 4 additions & 4 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ export default defineConfig({
use: { ...devices['Desktop Firefox'] }
},

//{
// name: 'webkit',
// use: { ...devices['Desktop Safari'] },
//},
{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},

/* Test against mobile viewports. */
// {
Expand Down
6 changes: 6 additions & 0 deletions src/assets/images/icons/flags/fr.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 22 additions & 17 deletions src/components/base/LanguageSwitcher.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,19 @@
data-testid="change-language-button">
<q-menu>
<q-list>
<q-item v-close-popup
<q-item v-for="{code, title, icon} in languages"
:key="code"
v-close-popup
clickable
dense

active-class="bg-grey-8"
:active="store.language === 'en'"
:title="t('base.language_switcher.languages.en.title')"
data-testid="change-language__english"
@click="changeLanguage('en')">
:active="store.language === code"
:title="title"
:data-testid="`change-language__${code}`"
@click="changeLanguage(code)">
<q-item-section>
<img :src="en" alt="English" height="16">
</q-item-section>
</q-item>
<q-item v-close-popup
clickable
active-class="bg-grey-8"
:active="store.language === 'cn'"
:title="t('base.language_switcher.languages.cn.title')"
data-testid="change-language__chinese"
@click="changeLanguage('cn')">
<q-item-section>
<img :src="cn" alt="Chinese" height="16">
<img :src="icon" :alt="title" height="16">
</q-item-section>
</q-item>
</q-list>
Expand All @@ -33,6 +26,7 @@
<script setup lang="ts">
import en from '../../assets/images/icons/flags/en.svg'
import cn from '../../assets/images/icons/flags/cn.svg'
import fr from '../../assets/images/icons/flags/fr.svg'
import { useI18nStore } from '../../store/i18n'
import { useTranslation } from '../../composables/i18n.ts'
import { ValidLocale } from '../../consts.ts'
Expand All @@ -46,4 +40,15 @@
store.setLanguage(lang)
router.go(0)
}
type Language = {
code: ValidLocale
title: string
icon: string
}
const languages: Language[] = [
{ code: 'en', title: t('base.language_switcher.languages.en.title'), icon: en },
{ code: 'cn', title: t('base.language_switcher.languages.cn.title'), icon: cn },
{ code: 'fr', title: t('base.language_switcher.languages.fr.title'), icon: fr }
]
</script>
5 changes: 3 additions & 2 deletions src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ export const REQUEST_DEFAULT_HEADERS = {
export const SUPPORTED_COUNTRY_LOCALES: Record<string, ValidLocale> = {
en: 'en',
cn: 'cn',
zh: 'cn'
zh: 'cn',
fr: 'fr'
}
export type ValidLocale = 'en' | 'cn'
export type ValidLocale = 'en' | 'cn' | 'fr'
export const DEFAULT_LOCALE: ValidLocale = 'en'

export const DEFAULT_ROWS_PER_PAGE = [10, 20, 100, 0]
Expand Down
3 changes: 3 additions & 0 deletions src/locales/cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
},
"cn": {
"title": "设置为中文"
},
"fr": {
"title": "法语"
}
}
},
Expand Down
3 changes: 3 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
},
"cn": {
"title": "Chinese"
},
"fr": {
"title": "French"
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/vue-i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { createI18n } from 'vue-i18n'
import en from '../locales/en.json'
import cn from '../locales/cn.json'
import fr from '../locales/fr.json'
import { useI18nStore } from '../store/i18n'

export const vueI18n = () => {
Expand All @@ -15,7 +16,7 @@ export const vueI18n = () => {
legacy: false,
locale: language,
fallbackLocale: 'en',
messages: { en, cn },
messages: { en, cn, fr },
warnHtmlMessage: false
})
}
2 changes: 1 addition & 1 deletion tests/e2e/tests/pages/Base.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test.describe('base', () => {
await openElasticvue(page)
page.getByTestId('change-language-button').click()

await expect(page.getByTestId('change-language__english')).toHaveClass(/q-item--active/)
await expect(page.getByTestId('change-language__en')).toHaveClass(/q-item--active/)
})
})
})
Expand Down

0 comments on commit cb2ff0d

Please sign in to comment.