Skip to content

Commit

Permalink
feat: add basic i18n support
Browse files Browse the repository at this point in the history
  • Loading branch information
maybeanerd committed Sep 11, 2023
1 parent e93e9aa commit 339d4a0
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 20 deletions.
19 changes: 1 addition & 18 deletions components/header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@
</div>
<div class="flex space-x-4">
<ThemePicker class="my-auto" />
<NSelect
v-model="selectedLanguage"
:options="languages"
default-value="en"
class="w-16"
/>
<LanguagePicker />
</div>
</div>
</template>
Expand All @@ -33,16 +28,4 @@ function toggleMenu () {
isOpen.value = !isOpen.value;
}
const selectedLanguage = ref('en');
const languages = [
{
label: 'EN',
value: 'en',
},
{
label: 'DE',
value: 'de',
},
];
</script>
22 changes: 22 additions & 0 deletions components/languagePicker.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<template>
<NSelect
v-model="locale"
:options="languages"
default-value="en"
class="w-16"
@update:value="updateLocale"
/>
</template>

<script setup lang="ts">
const { locale, availableLocales } = useI18n();
const languages = availableLocales.map(locale => ({
label: locale.toUpperCase(),
value: locale,
}));
function updateLocale (newLocale:string) {
locale.value = newLocale;
}
</script>
6 changes: 4 additions & 2 deletions components/profile/project/item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
:name="props.name"
:image-path="props.project.image"
/>
<ProfileProjectFact :title="'Role'" :value="props.project.role" />
<ProfileProjectFact :title="t('project.role')" :value="props.project.role" />
<ProfileProjectFact
:title="'Description'"
:value="props.project.description"
/>
<!-- TODO move description to a dedicated space -->
<ProfileProjectFact
v-if="props.project.technologies"
:title="'Technologies'"
:title="t('project.technologies')"
:value="props.project.technologies"
/>
<!-- TODO embed link nicely -->
Expand All @@ -42,6 +42,8 @@
<script setup lang="ts">
import type { Project } from '~/server/profile.types';
const { t } = useI18n();
const props = defineProps<{ project: Project; name: string }>();
function stringifyTimeframe (timeframe: Project['timeframe']) {
Expand Down
11 changes: 11 additions & 0 deletions i18n.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { en } from './locales/en';
import { de } from './locales/de';

export default defineI18nConfig(() => ({
legacy: false,
locale: 'en',
messages: {
en,
de,
},
}));
6 changes: 6 additions & 0 deletions locales/de.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const de = {
project: {
role: 'Rolle',
technologies: 'Technologien',
},
};
6 changes: 6 additions & 0 deletions locales/en.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const en = {
project: {
role: 'Role',
technologies: 'Technologies',
},
};
2 changes: 2 additions & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ export default defineNuxtConfig({
tailwindcss: {
exposeConfig: true,
},
i18n: {
},
});

0 comments on commit 339d4a0

Please sign in to comment.