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

🐛 ♻️ trying to fix i18n with ssr #28

Merged
merged 10 commits into from
Oct 19, 2023
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
.vitepress/dist
.vitepress/.temp
.vitepress/cache
node_modules
25 changes: 25 additions & 0 deletions .vitepress/components/TagChip.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<script setup>

import {TAG_PROP} from "../theme/enhancements/i18n/utility/tags.ts";
FabianWilms marked this conversation as resolved.
Show resolved Hide resolved
import {useTranslator} from "./Translator.ts";

const props = defineProps({
tag: {
type: String,
required: true
}
})

const i18nSelectorTags = TAG_PROP;

const { t } = useTranslator();
</script>

<template>
<v-chip
:value="tag"
filter
>
{{ t(`${i18nSelectorTags}.${tag}`) }}
</v-chip>
</template>
9 changes: 4 additions & 5 deletions .vitepress/components/TagFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import {ref} from "vue";
import {computed} from "vue";
import {data} from "../software.data.js";
import TagChip from "./TagChip.vue";

const props = defineProps({
modelValue: {
Expand Down Expand Up @@ -39,14 +40,12 @@ const allTags = computed(() => {
@update:modelValue="$emit('update:modelValue', $event)"
multiple
>
<v-chip
<tag-chip
v-for="(tag, index) in (availableTags.length > 0 ? availableTags : allTags)"
:key="index"
:value="tag"
:tag="tag"
filter
>
{{ tag }}
</v-chip>
/>
</v-chip-group>
</template>

Expand Down
8 changes: 4 additions & 4 deletions .vitepress/components/TagTile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@
<div
class="chip-group"
>
<v-chip
<tag-chip
v-for="(tag, index) in page.frontmatter.tags"
:key="index"
>
{{ tag }}
</v-chip>
:tag="tag"
/>
</div>
</div>
</v-card-text>
Expand All @@ -54,6 +53,7 @@ import {computed} from "vue";
import {data} from '../software.data.js'
import {withBase} from "vitepress";
import SoftwareImageAvatar from "./SoftwareImageAvatar.vue";
import TagChip from "./TagChip.vue";

const props = defineProps({
tagNames: {
Expand Down
35 changes: 35 additions & 0 deletions .vitepress/components/Translator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {useData} from "vitepress";
import {messages} from "../theme/enhancements/i18n/i18n";
FabianWilms marked this conversation as resolved.
Show resolved Hide resolved

export function useTranslator() {

const FALLBACK_LANG = 'en';
const TRANSLATION_KEY_JSON_PATH_SEPARATOR = '.';

const { lang } = useData();

function t(translationKey: String): String {
let langMap;

if(Object.keys(messages).indexOf(lang.value) != -1) {
langMap = messages[lang.value];
} else {
langMap = messages[FALLBACK_LANG];
}

let result = langMap;

translationKey.split(TRANSLATION_KEY_JSON_PATH_SEPARATOR ).forEach(key => {
if(result.hasOwnProperty(key)) {
result = result[key];
} else {
result = translationKey;
}
});

return result;
}

// expose managed state as return value
return { t }
}
9 changes: 9 additions & 0 deletions .vitepress/theme/enhancements/i18n/i18n.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { deMessages } from "./lang/de";
import { enMessages } from "./lang/en";

export const DEFAULT_LANG = "en";

export const messages = {
de: deMessages,
en: enMessages
}
24 changes: 24 additions & 0 deletions .vitepress/theme/enhancements/i18n/lang/de.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { localizedMessagesType } from "../utility/types";
FabianWilms marked this conversation as resolved.
Show resolved Hide resolved

export const deMessages: localizedMessagesType = {
tags: {
cicd: "CI/CD",
cms: "CMD",
client: "Client",
eigenentwicklung: 'Eigenentwicklung',
foss: "FOSS",
infrastruktur: "Infrastruktur",
keycloak: "Keycloak",
kooperation: "Kooperation",
monitoring: "Monitoring",
opencore: "Opencore",
opengovernment: "Open Government",
refarchinfrastruktur: "RefArch Infrastruktur",
server: "Server",
schnittstelle: "Schnittstelle",
sponsor: "Sponsor",
support: "Support",
todo: "todo",
webanwendung: "Webanwendung"
}
};
24 changes: 24 additions & 0 deletions .vitepress/theme/enhancements/i18n/lang/en.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { localizedMessagesType } from "../utility/types";
FabianWilms marked this conversation as resolved.
Show resolved Hide resolved

export const enMessages: localizedMessagesType = {
tags: {
cicd: "CI/CD",
cms: "CMS",
client: "Client",
eigenentwicklung: 'Inhouse',
foss: "FOSS",
infrastruktur: "Infrastructure",
keycloak: "Keycloak",
kooperation: "Cooperation",
monitoring: "Monitoring",
opencore: "Opencore",
opengovernment: "Open Government",
refarchinfrastruktur: "RefArch Infrastructure",
server: "Server",
schnittstelle: "Interface",
sponsor: "Sponsor",
support: "Support",
todo: "todo",
webanwendung: "Web-App"
}
};
24 changes: 24 additions & 0 deletions .vitepress/theme/enhancements/i18n/utility/tags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const TAG_PROP = "tags";

export interface Tags {
[TAG_PROP]: {
cicd: string,
cms: string,
client: string,
eigenentwicklung: string,
foss: string,
infrastruktur: string,
keycloak: string,
kooperation: string,
monitoring: string,
opencore: string,
opengovernment: string,
refarchinfrastruktur: string,
server: string,
schnittstelle: string,
sponsor: string,
support: string,
todo: string,
webanwendung: string,
}
}
4 changes: 4 additions & 0 deletions .vitepress/theme/enhancements/i18n/utility/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { DefaultLocaleMessageSchema } from "vue-i18n";
import { Tags } from "./tags";

export type localizedMessagesType = DefaultLocaleMessageSchema & Tags;