[ENG-1605] updater i18n (#2123)

* updater i18n

* more translations

* interpolate version number in translations

* [ENG-1598] Don't show update toast if no previous version (#2125)

don't show update toast if no previous version
This commit is contained in:
Brendan Allan
2024-02-28 00:17:06 +08:00
committed by GitHub
parent 399b8264f4
commit 068c6dd169
13 changed files with 157 additions and 53 deletions

View File

@@ -2,7 +2,7 @@ import { createMemoryHistory } from '@remix-run/router';
import { QueryClientProvider } from '@tanstack/react-query';
import { listen } from '@tauri-apps/api/event';
import { appWindow } from '@tauri-apps/api/window';
import { startTransition, useEffect, useMemo, useRef, useState } from 'react';
import { PropsWithChildren, startTransition, useEffect, useMemo, useRef, useState } from 'react';
import { createPortal } from 'react-dom';
import { CacheProvider, createCache, RspcProvider } from '@sd/client';
import {
@@ -18,10 +18,13 @@ import { RouteTitleContext } from '@sd/interface/hooks/useRouteTitle';
import '@sd/ui/style/style.scss';
import { useLocale } from '@sd/interface/hooks';
import { commands, events } from './commands';
import { platform } from './platform';
import { queryClient } from './query';
import { createMemoryRouterWithHistory } from './router';
import { createUpdater } from './updater';
// TODO: Bring this back once upstream is fixed up.
// const client = hooks.createClient({
@@ -53,20 +56,18 @@ export default function App() {
return (
<RspcProvider queryClient={queryClient}>
<PlatformProvider platform={platform}>
<QueryClientProvider client={queryClient}>
<CacheProvider cache={cache}>
{startupError ? (
<ErrorPage
message={startupError}
submessage="Error occurred starting up the Spacedrive core"
/>
) : (
<AppInner />
)}
</CacheProvider>
</QueryClientProvider>
</PlatformProvider>
<QueryClientProvider client={queryClient}>
<CacheProvider cache={cache}>
{startupError ? (
<ErrorPage
message={startupError}
submessage="Error occurred starting up the Spacedrive core"
/>
) : (
<AppInner />
)}
</CacheProvider>
</QueryClientProvider>
</RspcProvider>
);
}
@@ -203,25 +204,45 @@ function AppInner() {
}}
>
<SpacedriveInterfaceRoot>
{tabs.map((tab, index) =>
createPortal(
<SpacedriveRouterProvider
key={tab.id}
routing={{
routes,
visible: selectedTabIndex === tabs.indexOf(tab),
router: tab.router,
currentIndex: tab.currentIndex,
tabId: tab.id,
maxIndex: tab.maxIndex
}}
/>,
tab.element
)
)}
<div ref={ref} />
<PlatformUpdaterProvider>
{tabs.map((tab, index) =>
createPortal(
<SpacedriveRouterProvider
key={tab.id}
routing={{
routes,
visible: selectedTabIndex === tabs.indexOf(tab),
router: tab.router,
currentIndex: tab.currentIndex,
tabId: tab.id,
maxIndex: tab.maxIndex
}}
/>,
tab.element
)
)}
<div ref={ref} />
</PlatformUpdaterProvider>
</SpacedriveInterfaceRoot>
</TabsContext.Provider>
</RouteTitleContext.Provider>
);
}
function PlatformUpdaterProvider(props: PropsWithChildren) {
const { t } = useLocale();
return (
<PlatformProvider
platform={useMemo(
() => ({
...platform,
updater: window.__SD_UPDATER__ ? createUpdater(t) : undefined
}),
[]
)}
>
{props.children}
</PlatformProvider>
);
}

View File

@@ -75,7 +75,6 @@ export const platform = {
cb(e.payload);
}),
userHomeDir: homeDir,
updater: window.__SD_UPDATER__ ? createUpdater() : undefined,
auth: {
start(url) {
open(url);
@@ -83,4 +82,4 @@ export const platform = {
},
...commands,
landingApiOrigin: env.VITE_LANDING_ORIGIN
} satisfies Platform;
} satisfies Omit<Platform, 'updater'>;

View File

@@ -1,6 +1,7 @@
import { listen } from '@tauri-apps/api/event';
import { proxy, useSnapshot } from 'valtio';
import { UpdateStore } from '@sd/interface';
import { useLocale } from '@sd/interface/hooks';
import { toast, ToastId } from '@sd/ui';
import { commands } from './commands';
@@ -12,7 +13,7 @@ declare global {
}
}
export function createUpdater() {
export function createUpdater(t: ReturnType<typeof useLocale>['t']) {
if (!window.__SD_UPDATER__) return;
const updateStore = proxy<UpdateStore>({
@@ -46,11 +47,13 @@ export function createUpdater() {
toast.info(
(_id) => {
const { t } = useLocale();
id = _id;
return {
title: 'New Update Available',
body: `Version ${update.version}`
title: t('new_update_available'),
body: t('version', { version: update.version })
};
},
{
@@ -59,7 +62,7 @@ export function createUpdater() {
},
duration: 10 * 1000,
action: {
label: 'Update',
label: t('update'),
onClick: installUpdate
}
}
@@ -76,11 +79,11 @@ export function createUpdater() {
const promise = commands.installUpdate();
toast.promise(promise, {
loading: 'Downloading Update',
success: 'Update Downloaded. Restart Spacedrive to install',
loading: t('downloading_update'),
success: t('update_downloaded'),
error: (e: any) => (
<>
<p>Failed to download update</p>
<p>{t('failed_to_download_update')}</p>
<p className="text-gray-300">Error: {e.toString()}</p>
</>
)
@@ -93,6 +96,7 @@ export function createUpdater() {
async function runJustUpdatedCheck(onViewChangelog: () => void) {
const version = window.__SD_DESKTOP_VERSION__;
const lastVersion = localStorage.getItem(SD_VERSION_LOCALSTORAGE);
if (!lastVersion) return;
if (lastVersion !== version) {
localStorage.setItem(SD_VERSION_LOCALSTORAGE, version);
@@ -111,13 +115,13 @@ export function createUpdater() {
toast.success(
{
title: `Updated successfully, you're on version ${version}`,
title: t('updated_successfully', { version }),
body: tagline
},
{
duration: 10 * 1000,
action: {
label: 'View Changes',
label: t('view_changes'),
onClick: onViewChangelog
}
}

View File

@@ -429,5 +429,13 @@
"your_account": "Ваш уліковы запіс",
"your_account_description": "Уліковы запіс Spacedrive і інфармацыя.",
"your_local_network": "Ваша лакальная сетка",
"your_privacy": "Ваша прыватнасць"
"your_privacy": "Ваша прыватнасць",
"new_update_available": "Новая абнаўленне даступна!",
"version": "Версія {{version}}",
"downloading_update": "Загрузка абнаўлення",
"update_downloaded": "Абнаўленне загружана. Перазагрузіце Spacedrive для усталявання",
"failed_to_download_update": "Не ўдалося загрузіць абнаўленне",
"updated_successfully": "Паспяхова абнавіліся, вы на версіі {{version}}",
"view_changes": "Праглядзець змены",
"update": "Абнаўленне"
}

View File

@@ -428,5 +428,13 @@
"your_account": "Ihr Konto",
"your_account_description": "Spacedrive-Konto und -Informationen.",
"your_local_network": "Ihr lokales Netzwerk",
"your_privacy": "Ihre Privatsphäre"
"your_privacy": "Ihre Privatsphäre",
"new_update_available": "Neues Update verfügbar!",
"version": "Version {{version}}",
"downloading_update": "Update wird heruntergeladen",
"update_downloaded": "Update heruntergeladen. Starten Sie Spacedrive neu, um zu installieren",
"failed_to_download_update": "Update konnte nicht heruntergeladen werden",
"updated_successfully": "Erfolgreich aktualisiert, Sie verwenden jetzt Version {{version}}",
"view_changes": "Änderungen anzeigen",
"update": "Aktualisieren"
}

View File

@@ -429,5 +429,13 @@
"your_account": "Your account",
"your_account_description": "Spacedrive account and information.",
"your_local_network": "Your Local Network",
"your_privacy": "Your Privacy"
"your_privacy": "Your Privacy",
"new_update_available": "New Update Available!",
"version": "Version {{version}}",
"downloading_update": "Downloading Update",
"update_downloaded": "Update Downloaded. Restart Spacedrive to install",
"failed_to_download_update": "Failed to download update",
"updated_successfully": "Updated successfully, you're on version {{version}}",
"view_changes": "View Changes",
"update": "Update"
}

View File

@@ -428,5 +428,13 @@
"your_account": "Tu cuenta",
"your_account_description": "Cuenta de Spacedrive e información.",
"your_local_network": "Tu Red Local",
"your_privacy": "Tu Privacidad"
"your_privacy": "Tu Privacidad",
"new_update_available": "¡Nueva actualización disponible!",
"version": "Versión {{version}}",
"downloading_update": "Descargando actualización",
"update_downloaded": "Actualización descargada. Reinicia Spacedrive para instalar",
"failed_to_download_update": "Error al descargar la actualización",
"updated_successfully": "Actualizado correctamente, estás en la versión {{version}}",
"view_changes": "Ver cambios",
"update": "Actualizar"
}

View File

@@ -427,5 +427,13 @@
"your_account": "Votre compte",
"your_account_description": "Compte et informations Spacedrive.",
"your_local_network": "Votre réseau local",
"your_privacy": "Votre confidentialité"
"your_privacy": "Votre confidentialité",
"new_update_available": "Nouvelle mise à jour disponible !",
"version": "Version {{version}}",
"downloading_update": "Téléchargement de la mise à jour",
"update_downloaded": "Mise à jour téléchargée. Redémarrez Spacedrive pour installer",
"failed_to_download_update": "Échec du téléchargement de la mise à jour",
"updated_successfully": "Mise à jour réussie, vous êtes en version {{version}}",
"view_changes": "Voir les changements",
"update": "Mettre à jour"
}

View File

@@ -428,5 +428,13 @@
"your_account": "Je account",
"your_account_description": "Spacedrive account en informatie.",
"your_local_network": "Je Lokale Netwerk",
"your_privacy": "Jouw Privacy"
"your_privacy": "Jouw Privacy",
"new_update_available": "Nieuwe update beschikbaar!",
"version": "Versie {{version}}",
"downloading_update": "Update wordt gedownload",
"update_downloaded": "Update gedownload. Herstart Spacedrive om te installeren",
"failed_to_download_update": "Update kon niet worden gedownload",
"updated_successfully": "Succesvol bijgewerkt, je gebruikt nu versie {{version}}",
"view_changes": "Bekijk wijzigingen",
"update": "Bijwerken"
}

View File

@@ -429,5 +429,13 @@
"your_account": "Ваш аккаунт",
"your_account_description": "Учетная запись Spacedrive и информация.",
"your_local_network": "Ваша локальная сеть",
"your_privacy": "Ваша конфиденциальность"
"your_privacy": "Ваша конфиденциальность",
"new_update_available": "Доступно новое обновление!",
"version": "Версия {{version}}",
"downloading_update": "Загрузка обновления",
"update_downloaded": "Обновление загружено. Перезапустите Spacedrive для установки",
"failed_to_download_update": "Не удалось загрузить обновление",
"updated_successfully": "Успешно обновлено, вы используете версию {{version}}",
"view_changes": "Просмотреть изменения",
"update": "Обновить"
}

View File

@@ -428,5 +428,13 @@
"your_account": "Hesabınız",
"your_account_description": "Spacedrive hesabınız ve bilgileri.",
"your_local_network": "Yerel Ağınız",
"your_privacy": "Gizliliğiniz"
"your_privacy": "Gizliliğiniz",
"new_update_available": "Yeni Güncelleme Mevcut!",
"version": "Sürüm {{version}}",
"downloading_update": "Güncelleme İndiriliyor",
"update_downloaded": "Güncelleme İndirildi. Yüklemek için Spacedrive'ı yeniden başlatın",
"failed_to_download_update": "Güncelleme indirme başarısız",
"updated_successfully": "Başarıyla güncellendi, şu anda {{version}} sürümündesiniz",
"view_changes": "Değişiklikleri Görüntüle",
"update": "Güncelleme"
}

View File

@@ -428,5 +428,13 @@
"your_account": "您的账户",
"your_account_description": "Spacedrive账号和信息。",
"your_local_network": "您的本地网络",
"your_privacy": "您的隐私"
"your_privacy": "您的隐私",
"new_update_available": "新版本可用!",
"version": "版本 {{version}}",
"downloading_update": "下载更新",
"update_downloaded": "更新已下载。重新启动 Spacedrive 以安装",
"failed_to_download_update": "无法下载更新",
"updated_successfully": "成功更新,您当前使用的是版本 {{version}}",
"view_changes": "查看更改",
"update": "更新"
}

View File

@@ -427,5 +427,13 @@
"your_account": "您的帳戶",
"your_account_description": "Spacedrive帳戶和資訊。",
"your_local_network": "您的本地網路",
"your_privacy": "您的隱私"
"your_privacy": "您的隱私",
"new_update_available": "新版本可用!",
"version": "版本 {{version}}",
"downloading_update": "下載更新",
"update_downloaded": "更新已下載。重新啟動 Spacedrive 進行安裝",
"failed_to_download_update": "無法下載更新",
"updated_successfully": "成功更新,您目前使用的是版本 {{version}}",
"view_changes": "檢視變更",
"update": "更新"
}