Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(i18n): use same languages names in display and translations sections (settings/language) #2817

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions components/settings/SettingsTranslations.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script lang="ts" setup>
import ISO6391 from 'iso-639-1'
import { getDisplayName, supportedTranslationLanguages } from 'virtual:iso-639-1'

const supportedTranslationLanguages = ISO6391.getLanguages([...supportedTranslationCodes])
const userSettings = useUserSettings()

const language = ref<string | null>(null)
Expand Down Expand Up @@ -37,7 +36,7 @@ function removeDisabledTranslation(code: string) {
<div class="ms-4">
<ul>
<li v-for="langCode in userSettings.disabledTranslationLanguages" :key="langCode" class="flex items-center">
<div>{{ ISO6391.getNativeName(langCode) }}</div>
<div>{{ getDisplayName(langCode) }}</div>
<button class="btn-text" type="button" :title="$t('settings.language.translations.remove')" @click.prevent="removeDisabledTranslation(langCode)">
<span class="block i-ri:close-line" aria-hidden="true" />
</button>
Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions iso-639-1.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare module 'virtual:iso-639-1' {
export interface AvailableLanguages {
code: string
nativeName: string
}
export const supportedTranslationLanguages: AvailableLanguages[]
export function getDisplayName(code: string): string
}
30 changes: 30 additions & 0 deletions modules/iso-639-1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { addVitePlugin, defineNuxtModule } from '@nuxt/kit'
import { currentLocales } from '../config/i18n'

const virtualName = 'virtual:iso-639-1'
const resolvedVirtualName = `\0${virtualName}`

export default defineNuxtModule({
setup() {
addVitePlugin({
name: 'elk:iso-639-1',
enforce: 'pre',
resolveId(id) {
return id === virtualName ? resolvedVirtualName : null
},
async load(id) {
if (id === resolvedVirtualName) {
return `const languagesNames = ${JSON.stringify(currentLocales.reduce((acc, l) => {
acc[l.code] = l.name as string
return acc
}, {} as Record<string, string>))};
export const supportedTranslationLanguages = Object.entries(languagesNames).map(([code, nativeName]) => ({ code, nativeName }));
export function getDisplayName(code) {
return languagesNames[code] ?? new Intl.DisplayNames([code], { type: 'language' }).of(code);
}
`
}
},
})
},
})
1 change: 1 addition & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default defineNuxtConfig({
'@nuxt/test-utils/module',
...(isDevelopment || isWindows) ? [] : ['nuxt-security'],
'~/modules/emoji-mart-translation',
'~/modules/iso-639-1',
'~/modules/purge-comments',
'~/modules/build-env',
'~/modules/tauri/index',
Expand Down