Skip to content

Commit

Permalink
add i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
Armaldio committed Feb 26, 2025
1 parent c9fa349 commit 6c82b07
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 7 deletions.
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,9 @@
},
"debug.javascript.defaultRuntimeExecutable": {
"pwa-node": "c:\\users\\quent\\appdata\\local\\mise\\shims\\node"
}
},
"i18n-ally.localesPaths": [
"src/shared/i18n"
],
"i18n-ally.keystyle": "nested"
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
"valibot": "0.42.1",
"vee-validate": "4.14.4",
"vue-dompurify-html": "5.1.0",
"vue-i18n": "10",
"web-worker": "1.3.0",
"zod": "3.23.8"
},
Expand Down
40 changes: 40 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 31 additions & 6 deletions src/renderer/components/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<div class="card">
<Tabs value="0">
<TabList>
<Tab value="0">General</Tab>
<Tab value="1">Storage</Tab>
<Tab value="2">Integrations</Tab>
<Tab value="3">Advanced</Tab>
<Tab v-if="user.is_anonymous === false" value="4">Billing</Tab>
<Tab value="0">{{ t('settings.tabs.general') }}</Tab>
<Tab value="1">{{ t('settings.tabs.storage') }}</Tab>
<Tab value="2">{{ t('settings.tabs.integrations') }}</Tab>
<Tab value="3">{{ t('settings.tabs.advanced') }}</Tab>
<Tab v-if="user.is_anonymous === false" value="4">{{ t('settings.tabs.billing') }}</Tab>
</TabList>
<TabPanels>
<!-- General Tab -->
Expand All @@ -20,7 +20,23 @@
input-id="app-theme"
:model-value="false"
/>
<label for="app-theme" class="label">Dark theme</label>
<label for="app-theme" class="label">{{ t('settings.darkTheme') }}</label>
</div>
</div>
<div class="field">
<div class="field-switch">
<div class="locale-changer">
<select v-model="$i18n.locale">
<option
v-for="locale in $i18n.availableLocales"
:key="`locale-${locale}`"
:value="locale"
>
{{ locale }}
</option>
</select>
</div>
<label for="app-theme" class="label">Language</label>
</div>
</div>
</div>
Expand Down Expand Up @@ -122,6 +138,15 @@ import { supabase } from '@@/supabase'
import { useAuth } from '@renderer/store/auth'
import { format } from 'date-fns'
import { useI18n } from 'vue-i18n'
import { MessageSchema } from '@@/i18n-utils'
const { t } = useI18n<
{
message: MessageSchema
},
'en-US'
>()
const appSettings = useAppSettings()
const api = useAPI()
Expand Down
13 changes: 13 additions & 0 deletions src/renderer/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { router } from './router/router'

import { createPinia } from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import { createI18n } from 'vue-i18n'

import PrimeVue from 'primevue/config'
import Lara from '@primevue/themes/lara'
Expand All @@ -20,6 +21,7 @@ import ToastService from 'primevue/toastservice'
import ConfirmationService from 'primevue/confirmationservice'
import posthogPlugin from './plugins/posthog' //import the plugin.
import posthog from 'posthog-js'
import { en_US, fr_FR, MessageSchema } from '@@/i18n-utils'

if (window.isPackaged && process.env.TEST !== 'true') {
init(
Expand All @@ -41,6 +43,16 @@ if (window.isPackaged && process.env.TEST !== 'true') {
)
}

const i18n = createI18n<[MessageSchema], 'en-US' | 'fr-FR'>({
legacy: false,
locale: 'en-US',
fallbackLocale: 'en-US',
messages: {
'en-US': en_US,
'fr-FR': fr_FR
}
})

const pinia = createPinia()
pinia.use(piniaPluginPersistedstate)

Expand Down Expand Up @@ -139,5 +151,6 @@ app.use(ConfirmationService)
if (window.isPackaged && process.env.TEST !== 'true') {
app.use(posthogPlugin)
}
app.use(i18n)

app.mount('#app')
5 changes: 5 additions & 0 deletions src/shared/i18n-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import en_US from './i18n/en_US.json'
import fr_FR from './i18n/fr_FR.json'

type MessageSchema = typeof en_US
export { MessageSchema, en_US, fr_FR }
17 changes: 17 additions & 0 deletions src/shared/i18n/en_US.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"settings": {
"darkTheme": "Dark theme",
"language": "Language",
"languageOptions": {
"en": "English",
"fr": "French"
},
"tabs": {
"general": "General",
"storage": "Storage",
"integrations": "Integrations",
"advanced": "Advanced",
"billing": "Billing"
}
}
}
17 changes: 17 additions & 0 deletions src/shared/i18n/fr_FR.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"settings": {
"darkTheme": "Thème sombre",
"language": "Langue",
"languageOptions": {
"en": "Anglais",
"fr": "Français"
},
"tabs": {
"general": "Général",
"advanced": "Avancé",
"billing": "Facturation",
"integrations": "Intégrations",
"storage": "Stockage"
}
}
}

0 comments on commit 6c82b07

Please sign in to comment.