From 068c6dd169bc10eeffbae4e5247a0e7cb7dda5d7 Mon Sep 17 00:00:00 2001 From: Brendan Allan Date: Wed, 28 Feb 2024 00:17:06 +0800 Subject: [PATCH] [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 --- apps/desktop/src/App.tsx | 85 ++++++++++++++++++----------- apps/desktop/src/platform.ts | 3 +- apps/desktop/src/updater.tsx | 22 +++++--- interface/locales/by/common.json | 10 +++- interface/locales/de/common.json | 10 +++- interface/locales/en/common.json | 10 +++- interface/locales/es/common.json | 10 +++- interface/locales/fr/common.json | 10 +++- interface/locales/nl/common.json | 10 +++- interface/locales/ru/common.json | 10 +++- interface/locales/tr/common.json | 10 +++- interface/locales/zh-CN/common.json | 10 +++- interface/locales/zh-TW/common.json | 10 +++- 13 files changed, 157 insertions(+), 53 deletions(-) diff --git a/apps/desktop/src/App.tsx b/apps/desktop/src/App.tsx index 5f1dfa331..47e002d55 100644 --- a/apps/desktop/src/App.tsx +++ b/apps/desktop/src/App.tsx @@ -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 ( - - - - {startupError ? ( - - ) : ( - - )} - - - + + + {startupError ? ( + + ) : ( + + )} + + ); } @@ -203,25 +204,45 @@ function AppInner() { }} > - {tabs.map((tab, index) => - createPortal( - , - tab.element - ) - )} -
+ + {tabs.map((tab, index) => + createPortal( + , + tab.element + ) + )} +
+ ); } + +function PlatformUpdaterProvider(props: PropsWithChildren) { + const { t } = useLocale(); + + return ( + ({ + ...platform, + updater: window.__SD_UPDATER__ ? createUpdater(t) : undefined + }), + [] + )} + > + {props.children} + + ); +} diff --git a/apps/desktop/src/platform.ts b/apps/desktop/src/platform.ts index 67c2bb2cc..ad7ba3bc4 100644 --- a/apps/desktop/src/platform.ts +++ b/apps/desktop/src/platform.ts @@ -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; diff --git a/apps/desktop/src/updater.tsx b/apps/desktop/src/updater.tsx index c0a293e29..337097d41 100644 --- a/apps/desktop/src/updater.tsx +++ b/apps/desktop/src/updater.tsx @@ -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['t']) { if (!window.__SD_UPDATER__) return; const updateStore = proxy({ @@ -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) => ( <> -

Failed to download update

+

{t('failed_to_download_update')}

Error: {e.toString()}

) @@ -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 } } diff --git a/interface/locales/by/common.json b/interface/locales/by/common.json index de489fc69..00728f52c 100644 --- a/interface/locales/by/common.json +++ b/interface/locales/by/common.json @@ -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": "Абнаўленне" } diff --git a/interface/locales/de/common.json b/interface/locales/de/common.json index c8b50f05f..c710a72fc 100644 --- a/interface/locales/de/common.json +++ b/interface/locales/de/common.json @@ -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" } diff --git a/interface/locales/en/common.json b/interface/locales/en/common.json index 7dc18e7f2..861f0d3c3 100644 --- a/interface/locales/en/common.json +++ b/interface/locales/en/common.json @@ -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" } diff --git a/interface/locales/es/common.json b/interface/locales/es/common.json index a7e64f0a9..abff432aa 100644 --- a/interface/locales/es/common.json +++ b/interface/locales/es/common.json @@ -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" } diff --git a/interface/locales/fr/common.json b/interface/locales/fr/common.json index c5354b659..7102c1efb 100644 --- a/interface/locales/fr/common.json +++ b/interface/locales/fr/common.json @@ -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" } diff --git a/interface/locales/nl/common.json b/interface/locales/nl/common.json index a03a7d034..3fc8dabf9 100644 --- a/interface/locales/nl/common.json +++ b/interface/locales/nl/common.json @@ -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" } diff --git a/interface/locales/ru/common.json b/interface/locales/ru/common.json index be8fbcafa..2efdd3739 100644 --- a/interface/locales/ru/common.json +++ b/interface/locales/ru/common.json @@ -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": "Обновить" } diff --git a/interface/locales/tr/common.json b/interface/locales/tr/common.json index 1e29dde63..0202e19a1 100644 --- a/interface/locales/tr/common.json +++ b/interface/locales/tr/common.json @@ -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" } diff --git a/interface/locales/zh-CN/common.json b/interface/locales/zh-CN/common.json index 1db6ac440..e7a1f2d73 100644 --- a/interface/locales/zh-CN/common.json +++ b/interface/locales/zh-CN/common.json @@ -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": "更新" } diff --git a/interface/locales/zh-TW/common.json b/interface/locales/zh-TW/common.json index 915a0c916..cad8726b5 100644 --- a/interface/locales/zh-TW/common.json +++ b/interface/locales/zh-TW/common.json @@ -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": "更新" }