|
| 1 | +import { createSharedComposable, reactiveComputed } from '@vueuse/core' |
| 2 | +import { Fragment, customRef, h, ref } from 'vue' |
| 3 | +import { AppStorage } from '../storage' |
| 4 | +import { type NotificationReason } from '../constants' |
| 5 | + |
| 6 | +export type Locale = 'en' | 'tr' |
| 7 | + |
| 8 | +const en = { |
| 9 | + navigateToRepository: 'Navigate to repository', |
| 10 | + reloadNotifications: (shortcut: string) => `Reload notifications (${shortcut})`, |
| 11 | + more: 'More', |
| 12 | + changelog: 'Changelog', |
| 13 | + aNewVersionIsAvailable: 'A new version is available!', |
| 14 | + settings: 'Settings', |
| 15 | + signOut: 'Sign out', |
| 16 | + logOut: 'Log out', |
| 17 | + exitApp: 'Exit app', |
| 18 | + itsAllClear: 'It\'s all clear sir!', |
| 19 | + appearance: 'Appearance', |
| 20 | + theme: 'Theme', |
| 21 | + system: 'System', |
| 22 | + light: 'Light', |
| 23 | + dark: 'Dark', |
| 24 | + systemTitle: 'System', |
| 25 | + sounds: 'Sounds', |
| 26 | + openAtStartup: 'Open at startup', |
| 27 | + showSystemNotifications: 'Show system notifications', |
| 28 | + notificationsTitle: 'Notifications', |
| 29 | + showOnlyParticipating: 'Show only participating', |
| 30 | + showReadNotifications: 'Show read notifications', |
| 31 | + markAsReadOnOpen: 'Mark as read on open', |
| 32 | + markAsReadOpenDescription: 'When you open some notifications, Github marks them as read automaticlly, but for some it doesn\'t.', |
| 33 | + welcomeToGitification: 'Welcome to Gitification', |
| 34 | + loginViaGithub: 'Login via Github', |
| 35 | + oopsieCouldntLoad: 'Oopsie! Couldn\'t load notifications', |
| 36 | + refresh: 'Refresh', |
| 37 | + clearSelections: 'Clear selections', |
| 38 | + unsubscribe: 'Unsubscribe', |
| 39 | + open: 'Open', |
| 40 | + markAsRead: 'Mark as read', |
| 41 | + unsubscribeAll: 'Unsubscribe all', |
| 42 | + openAll: 'Open all', |
| 43 | + markAllAsRead: 'Mark all as read', |
| 44 | + selectAll: 'Select all', |
| 45 | + unselectAll: 'Unselect all', |
| 46 | + select: 'Select', |
| 47 | + unselect: 'Unselect', |
| 48 | + gitificationVersionIsAvailable: (version: string) => `Gitification ${version} is available!`, |
| 49 | + currentVersionIs: (version: string) => () => h(Fragment, null, [ |
| 50 | + 'Current version is ', |
| 51 | + h('b', null, version), |
| 52 | + ]), |
| 53 | + install: 'Install', |
| 54 | + reason: { |
| 55 | + assign: 'Assign', |
| 56 | + author: 'Author', |
| 57 | + comment: 'Comment', |
| 58 | + invitation: 'Invitation', |
| 59 | + manual: 'Manual', |
| 60 | + mention: 'Mention', |
| 61 | + review_requested: 'Review requested', |
| 62 | + security_alert: 'Security alert', |
| 63 | + state_change: 'State change', |
| 64 | + subscribed: 'Subscribed', |
| 65 | + team_mention: 'Team mention', |
| 66 | + ci_activity: 'CI activity', |
| 67 | + } satisfies Record<NotificationReason, string>, |
| 68 | + goBack: (shortcut: string) => `Go back (${shortcut})`, |
| 69 | + language: { |
| 70 | + title: 'Language', |
| 71 | + en: 'English', |
| 72 | + tr: 'Türkçe', |
| 73 | + }, |
| 74 | +} |
| 75 | + |
| 76 | +const tr: typeof en = { |
| 77 | + navigateToRepository: 'Repoya git', |
| 78 | + reloadNotifications: (shortcut: string) => `Bildirimleri yenile (${shortcut})`, |
| 79 | + more: 'Daha fazla', |
| 80 | + changelog: 'Yenilikler', |
| 81 | + aNewVersionIsAvailable: 'Yeni bir sürüm mevcut!', |
| 82 | + settings: 'Ayarlar', |
| 83 | + signOut: 'Çıkış yap', |
| 84 | + logOut: 'Çıkış yap', |
| 85 | + exitApp: 'Uygulamadan Çık', |
| 86 | + itsAllClear: 'Hepsi okundu!', |
| 87 | + appearance: 'Görünüm', |
| 88 | + theme: 'Tema', |
| 89 | + system: 'Sistem', |
| 90 | + light: 'Açık', |
| 91 | + dark: 'Koyu', |
| 92 | + systemTitle: 'Sistem', |
| 93 | + sounds: 'Sesler', |
| 94 | + openAtStartup: 'Başlangıçta aç', |
| 95 | + showSystemNotifications: 'Sistem bildirimleri göster', |
| 96 | + notificationsTitle: 'Bildirimler', |
| 97 | + showOnlyParticipating: 'Sadece dahil olduklarımı göster', |
| 98 | + showReadNotifications: 'Okunmuş bildirimleri göster', |
| 99 | + markAsReadOnOpen: 'Açınca okundu olarak işaretle', |
| 100 | + markAsReadOpenDescription: 'Bazı bildirimleri açınca Github otomatik olarak okundu olarak işaretliyor ama bazılarını işaretlemiyor. Bu ayar ile her zaman okundu olarak işaretleyebilirsin.', |
| 101 | + welcomeToGitification: 'Gitification\'a hoşgeldin', |
| 102 | + loginViaGithub: 'Github ile giriş yap', |
| 103 | + oopsieCouldntLoad: 'Tüh be! Bildirimler yüklenemedi', |
| 104 | + refresh: 'Yenile', |
| 105 | + clearSelections: 'Seçimleri temizle', |
| 106 | + unsubscribe: 'Aboneliği kaldır', |
| 107 | + open: 'Aç', |
| 108 | + markAsRead: 'Okundu olarak işaretle', |
| 109 | + unsubscribeAll: 'Tümünün aboneliğini kaldır', |
| 110 | + openAll: 'Tümünü aç', |
| 111 | + markAllAsRead: 'Tümünü okundu olarak işaretle', |
| 112 | + selectAll: 'Tümünü seç', |
| 113 | + unselectAll: 'Tüm seçimi kaldır', |
| 114 | + select: 'Seç', |
| 115 | + unselect: 'Seçimi kaldır', |
| 116 | + gitificationVersionIsAvailable: (version: string) => `Gitification ${version} yayında!`, |
| 117 | + currentVersionIs: (version: string) => () => h(Fragment, null, [ |
| 118 | + 'Şuanki versiyon ', |
| 119 | + h('b', null, version), |
| 120 | + ]), |
| 121 | + install: 'Yükle', |
| 122 | + reason: { |
| 123 | + assign: 'Atama', |
| 124 | + author: 'Yazar', |
| 125 | + comment: 'Yorum', |
| 126 | + invitation: 'Davet', |
| 127 | + manual: 'Manuel', |
| 128 | + mention: 'Bahsetme', |
| 129 | + review_requested: 'İnceleme İstendi', |
| 130 | + security_alert: 'Güvenlik Uyarısı', |
| 131 | + state_change: 'Durum Değişimi', |
| 132 | + subscribed: 'Abone Olundu', |
| 133 | + team_mention: 'Takım bahsetmesi', |
| 134 | + ci_activity: 'CI etkinliği', |
| 135 | + } satisfies Record<NotificationReason, string>, |
| 136 | + goBack: (shortcut: string) => `Geri (${shortcut})`, |
| 137 | + language: { |
| 138 | + title: 'Dil', |
| 139 | + en: 'English', |
| 140 | + tr: 'Türkçe', |
| 141 | + }, |
| 142 | +} |
| 143 | + |
| 144 | +const localeMap: Record<Locale, typeof en> = { en, tr } |
| 145 | + |
| 146 | +export const useI18n = createSharedComposable(() => { |
| 147 | + const currentLanguage = customRef<Locale>((track, trigger) => { |
| 148 | + const locale = ref<Locale>('tr') |
| 149 | + |
| 150 | + return { |
| 151 | + get() { |
| 152 | + track() |
| 153 | + return locale.value |
| 154 | + }, |
| 155 | + set(value) { |
| 156 | + locale.value = value |
| 157 | + AppStorage.set('language', value) |
| 158 | + trigger() |
| 159 | + }, |
| 160 | + } |
| 161 | + }) |
| 162 | + |
| 163 | + const t = reactiveComputed(() => localeMap[currentLanguage.value]) |
| 164 | + |
| 165 | + return { |
| 166 | + currentLanguage, |
| 167 | + t, |
| 168 | + } |
| 169 | +}) |
0 commit comments