diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index f49f06f..d776393 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1940,6 +1940,17 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "os_info" +version = "3.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "006e42d5b888366f1880eda20371fedde764ed2213dc8496f49622fa0c99cd5e" +dependencies = [ + "log", + "serde", + "winapi", +] + [[package]] name = "overload" version = "0.1.1" @@ -2965,6 +2976,19 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" +[[package]] +name = "sys-locale" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8a11bd9c338fdba09f7881ab41551932ad42e405f61d01e8406baea71c07aee" +dependencies = [ + "js-sys", + "libc", + "wasm-bindgen", + "web-sys", + "windows-sys 0.45.0", +] + [[package]] name = "system-configuration" version = "0.5.1" @@ -3110,6 +3134,7 @@ dependencies = [ "objc", "once_cell", "open", + "os_info", "percent-encoding", "rand 0.8.5", "raw-window-handle", @@ -3122,6 +3147,7 @@ dependencies = [ "serde_repr", "serialize-to-javascript", "state", + "sys-locale", "tar", "tauri-macros", "tauri-runtime", @@ -4004,6 +4030,15 @@ dependencies = [ "windows_x86_64_msvc 0.42.2", ] +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -4022,6 +4057,21 @@ dependencies = [ "windows-targets 0.52.0", ] +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + [[package]] name = "windows-targets" version = "0.48.5" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index eb47f3b..1003246 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -15,7 +15,7 @@ tauri-build = { version = "1.3.0", features = [] } [dependencies] serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } -tauri = { version = "1.3.0", features = [ "shell-open", "dialog-confirm", "http-api", "window-close"] } +tauri = { version = "1.3.0", features = [ "os-all", "shell-open", "dialog-confirm", "http-api", "window-close"] } zip = "0.6.6" tokio = { version = "1", features = [ "fs" ] } sha2 = "0.10.6" diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 699b3f7..f9b4a0d 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -22,6 +22,9 @@ }, "shell": { "open": "^https://fabulously-optimized.gitbook.io/modpack/readme/" + }, + "os": { + "all": true } }, "bundle": { diff --git a/src/lib/i18n.ts b/src/lib/i18n.ts new file mode 100644 index 0000000..f53a8b2 --- /dev/null +++ b/src/lib/i18n.ts @@ -0,0 +1,36 @@ +import { locale as getLocale } from '@tauri-apps/api/os'; +import { langs } from './lang'; + +let locale = navigator.language.split('-')[0]; +const defaultLocale = "en"; + +getLocale().then(systemLocale => { + if (systemLocale) + locale = systemLocale.split('-')[0] +}) + +export function trans(id: string, data?: Record) { + if (locale && langs[locale] && langs[locale][id]) { + const text = langs[locale][id]; + for (const key in data) { + if (Object.prototype.hasOwnProperty.call(data, key)) { + const element = data[key]; + if (element !== undefined) + text.replaceAll(`{{${key}}}`, element.toString()) + } + } + return text + } + if (langs[defaultLocale] && langs[defaultLocale][id]) { + const text = langs[defaultLocale][id]; + for (const key in data) { + if (Object.prototype.hasOwnProperty.call(data, key)) { + const element = data[key]; + if (element !== undefined) + text.replaceAll(`{{${key}}}`, element.toString()) + } + } + return text + } + return id +} \ No newline at end of file diff --git a/src/lib/lang/en.json b/src/lib/lang/en.json new file mode 100644 index 0000000..c0d44cc --- /dev/null +++ b/src/lib/lang/en.json @@ -0,0 +1,23 @@ +{ + "progress.clean_old": "Cleaning up old files", + "progress.load_pack": "Downloading modpack", + "progress.download_files": "Downloading mods", + "progress.download_file": "Downloading {{file}} ({{idx}}/{{total}})", + "progress.extract_overrides": "Extracting configuration files", + "progress.install_loader": "Installing mod loader", + "progress.add_profile": "Creating launcher profile", + "ui.loading-versions": "Loading versions...", + "ui.version-tooltip": "Vanilla Installer allows easy installation of all supported versions of Fabulously Optimized. For outdated versions, use a different launcher.", + "ui.isolate-profile": "Use a different .minecraft directory for this version?", + "ui.profile-dir-placeholder": "Leave blank to let the installer decide", + "ui.profile-dir-browse-label": "Browse folders", + "ui.install-button": "Install!", + "ui.installing": "Installing...", + "ui.installed": "Fabulously Optimized is installed!", + "ui.install-error": "An error occurred while installing Fabulously Optimized: {{errorMessage}}", + "ui.downgrade-msg": "You are attempting to downgrade the Minecraft version. This is NOT SUPPORTED by Mojang or Fabulously Optimized and it may cause world corruption or crashes.
If you want to do this safely, you should backup mods, config and saves folders to a different location and delete them from your .minecraft folder.
To skip this warning after backing up the folders, delete paigaldaja_meta.json from your .minecraft folder.", + "ui.confirm-downgrade": "Yes, I want to downgrade FO.", + "ui.downgrade-cancel": "Back", + "ui.downgrade-continue": "Continue", + "ui.confirm-exit": "Fabulously Optimized is installing. Are you sure you want to exit?" +} \ No newline at end of file diff --git a/src/lib/lang/index.ts b/src/lib/lang/index.ts new file mode 100644 index 0000000..78175dd --- /dev/null +++ b/src/lib/lang/index.ts @@ -0,0 +1,5 @@ +import en from "./en.json"; + +export const langs: Record> = { + en +}; \ No newline at end of file diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 569f05a..623f5a0 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -5,6 +5,7 @@ show_profile_dir_selector } from '$lib/installer'; import { get_project, list_versions, type Version } from '$lib/modrinth'; + import { trans } from '$lib/i18n'; import { listen } from '@tauri-apps/api/event'; import { appWindow } from '@tauri-apps/api/window'; import { confirm } from '@tauri-apps/api/dialog'; @@ -23,32 +24,34 @@ if (payload[1] == 'start') { switch (payload[0]) { case 'clean_old': - installProgress = 'Cleaning up old files'; + installProgress = trans('clean_old'); break; case 'load_pack': - installProgress = 'Downloading modpack'; + installProgress = trans('load_pack'); currentStep = 1; break; case 'download_files': - installProgress = 'Downloading mods'; + installProgress = trans('download_files'); totalMods = payload[2] as number; break; case 'download_file': - installProgress = `Downloading ${payload[3]} (${ - (payload[2] as number) + 1 - }/${totalMods})`; + installProgress = trans('download_file', { + file: payload[3], + idx: (payload[2] as number) + 1, + total: totalMods + }); currentStep = (payload[2] as number) + 2; break; case 'extract_overrides': - installProgress = 'Extracting configuration files'; + installProgress = trans('extract_overrides'); currentStep = totalMods + 2; break; case 'install_loader': - installProgress = 'Installing mod loader'; + installProgress = trans('install_loader'); currentStep = totalMods + 3; break; case 'add_profile': - installProgress = 'Creating launcher profile'; + installProgress = trans('add_profile'); currentStep = totalMods + 4; break; } @@ -56,13 +59,13 @@ }); function confirmUnload(ev: BeforeUnloadEvent) { ev.preventDefault(); - return (ev.returnValue = 'Fabulously Optimized is installing. Are you sure you want to exit?'); + return (ev.returnValue = trans("ui.confirm-exit")); } async function installPack() { addEventListener('beforeunload', confirmUnload); const unlisten = await appWindow.onCloseRequested(async (ev) => { const confirmed = await confirm( - 'Fabulously Optimized is installing. Are you sure you want to exit?' + trans("ui.confirm-exit") ); if (!confirmed) { // user did not confirm closing the window; let's prevent it @@ -185,7 +188,7 @@
- +
(state = 'preInstall')}>{trans('ui.downgrade-cancel')} {trans('ui.downgrade-continue')} {/if}