Skip to content
This repository has been archived by the owner on Jan 15, 2025. It is now read-only.

Addition of Multiple Languages, Refactor and Enhance Notification Store #924

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 30 additions & 37 deletions svelte/src/libs/stores/notifications.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,53 @@
import { writable } from "svelte/store";
import { nanoid } from "nanoid";

import { NotificationType } from "$libs/types";
import type { Notification } from "$libs/types";

import { listenToChannel, relaunch } from "@native";

export default function initNotificationStore() {
const notifications: Notification[] = [];
const { update, subscribe } = writable<Notification[]>([]);

const restartAlert = writable(false);

const remove = (id: string) => {
update((notifications) => notifications.filter((n) => n.id != id));
update((notifications) => notifications.filter((n) => n.id !== id));
};

listenToChannel("message", (data: any) => {
const { message, params }: { message: string; params: { [key: string]: string } } = data;
const add = (partialNotification: Partial<Notification>) => {
if (!partialNotification.message) {
throw new Error("Message is required for notification");
}

const notification: Notification = {
id: nanoid(6), // Increased from 4 to 6 for more uniqueness
i18n_key: partialNotification.i18n_key || "",
type: partialNotification.type || NotificationType.MESSAGE,
message: partialNotification.message,
...partialNotification
};

update((value) => {
const newNotification: Notification = {
id: nanoid(4),
message,
i18n_key: params["i18n_key"] || "",
type: NotificationType.ACTION_BANNER,
params
};
if (params.action) {
newNotification.callback_label = params.action.toUpperCase();
newNotification.callback = () => {
relaunch();
remove(newNotification.id); // not sure yet
};
}
return [...value, newNotification];
update((values) => [notification, ...values]);
};

listenToChannel("message", (data: { message: string; params: { [key: string]: string } }) => {
const { message, params } = data;

add({
message,
i18n_key: params.i18n_key || "",
type: NotificationType.ACTION_BANNER,
params,
callback_label: params.action ? params.action.toUpperCase() : undefined,
callback: params.action ? () => {
relaunch();
remove(nanoid(6)); // This might need adjustment
} : undefined
});
});

return {
notifications,
subscribe,
remove,
add: (partialNotification: Partial<Notification>) => {
if (!partialNotification.message) throw new Error("message is required");

const notification: Notification = {
id: nanoid(4),
i18n_key: partialNotification.i18n_key || "",
type: NotificationType.MESSAGE,
message: partialNotification.message || "",
...partialNotification
};

update((values) => [notification, ...values]);
},
add,
restartAlert
};
}
10 changes: 9 additions & 1 deletion svelte/src/libs/translations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ import bn from "./languages/bn.json";
import eu from "./languages/eu.json";
import ca from "./languages/ca.json";
import mn from "./languages/mn.json";
import ha from "./languages/ha.json";
import hi from "./languages/hi.json";
import sw from "./languages/sw.json";
import ur from "./languages/ur.json";

import * as customModifiers from "./modifiers";

Expand Down Expand Up @@ -107,7 +111,11 @@ const languages = [
bn,
eu,
ca,
mn
mn,
ha,
hi,
sw,
ur
];

const langs: { [lang: string]: string } = {};
Expand Down
101 changes: 101 additions & 0 deletions svelte/src/libs/translations/languages/ha.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"id": "ha",
"label": "Hausa",
"translations": {
"store-search-placeholder": "nemo kaya",
"action": {
"update": "sabunta",
"cancel": "soke"
},
"package": {
"update-all": "SABUNTA DUKA",
"cta-AVAILABLE": "SAKA",
"cta-INSTALLED": "AN SAKA",
"cta-INSTALLING": "ANA SAKA",
"cta-UNINSTALLED": "SAKE SAKA",
"cta-UNINSTALL": "CIRE",
"cta-NEEDS_UPDATE": "SABUNTA",
"cta-UPDATING": "ANA SABUNTAWA",
"cta-UPDATED": "AN SABUNTA",
"cta-PRUNE": "RAGE",
"cta-PRUNING": "ANA RAGE",
"open": "BUDE",
"open-in-terminal": "BUDE A TERMINAL",
"local-package": "kayan gida",
"not-in-pantry": "ba a ƙara ga wurin ajiya ba"
},
"footer": {
"quick-links-title": "hanyoyin sauri",
"about-tea-store": "game da shagon shayi",
"report-a-problem": "ba da rahoto kan matsala",
"visit-website": "ziyarci tea.xyz",
"terms-services": "sharuɗɗa da huɗuma",
"privacy-policy": "manufar sirri"
},
"documentation": {
"title": "takardu",
"workshops": "ayyukan hannu"
},
"view-all": "duba duka",
"sorting": {
"label": "Tsara ta",
"popularity": "Mafi shahara",
"most-recent": "Na baya-bayan nan"
},
"common": {
"home": "gida",
"all": "Duka",
"articles": "Labarai",
"workshops": "Ayyukan hannu",
"metadata": "Metadata",
"homepage": "Shafin Gida",
"documentation": "Takardu",
"github-repository": "Ma'ajiyar GitHub",
"repository": "Ma'ajiya",
"contributors": "Masu taimako",
"view-on-github": "DUBA A GITHUB"
},
"tabs": {
"details": "pkg",
"cli": "cli",
"gui": "gui"
},
"notification": {
"update-header": "sabunta tea/gui zuwa {{version}}?",
"gui-restarting": "Ci gaba zai sa manhajar ta sake kunna bayan an gama. Ka tabbatar ba ka da wani aiki da ke gudana. Kana son ci gaba?",
"gui-restart": "sake kunna"
},
"side-menu-title": {
"discover": "gano",
"all": "Duk Kayaye",
"installed": "Kayaye da aka Saka",
"installed_updates_available": "Akwai Sabuntawa",
"recently_updated": "An Sabunta Kwanan nan",
"new_packages": "Sabuwar Kaya",
"popular": "Shahararru",
"featured": "Zaɓaɓɓu",
"essentials": "Muhimmai",
"starstruck": "Manyan Starstruck",
"made_by_tea": "an yi ta shayi",
"local_packages": "Kayan Gida"
},
"tags": {
"discover": "gano",
"all": "duk kayaye",
"installed": "an saka",
"installed_updates_available": "Akwai sabuntawa",
"recently_updated": "An sabunta kwanan nan",
"new_packages": "Sabuwar kaya",
"popular": "Shahararru",
"featured": "Zaɓaɓɓu",
"essentials": "Muhimmai",
"starstruck": "Starstruck",
"made_by_tea": "An yi ta shayi",
"local_packages": "Kayan Gida"
},
"discover": {
"featured_title": "muhimman AI na gida",
"featured_description": "Bincika duniyar AI na gida. Wannan shine dandamalinku don gwada kayan aikin AI da suka shahara kamar AutoGPT da Stable Diffusion Web UI, kai tsaye daga tsarin ku na gida. Fara ayyukan AI naku yayin da kuke kiyaye bayaninku lafiya kuma amintacce, tare da 'yancin yin daidaitawa yadda kuke so."
}
}
}
101 changes: 101 additions & 0 deletions svelte/src/libs/translations/languages/hi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"id": "hi",
"label": "हिन्दी",
"translations": {
"store-search-placeholder": "पैकेज खोजें",
"action": {
"update": "अपडेट करें",
"cancel": "रद्द करें"
},
"package": {
"update-all": "सभी अपडेट करें",
"cta-AVAILABLE": "इंस्टॉल करें",
"cta-INSTALLED": "इंस्टॉल किया गया",
"cta-INSTALLING": "इंस्टॉल हो रहा है",
"cta-UNINSTALLED": "पुनः इंस्टॉल करें",
"cta-UNINSTALL": "अनइंस्टॉल करें",
"cta-NEEDS_UPDATE": "अपडेट करें",
"cta-UPDATING": "अपडेट हो रहा है",
"cta-UPDATED": "अपडेटेड",
"cta-PRUNE": "प्रून करें",
"cta-PRUNING": "प्रून हो रहा है",
"open": "खोलें",
"open-in-terminal": "टर्मिनल में खोलें",
"local-package": "स्थानीय पैकेज",
"not-in-pantry": "पैंट्री में नहीं जोड़ा गया"
},
"footer": {
"quick-links-title": "त्वरित लिंक",
"about-tea-store": "चाय स्टोर के बारे में",
"report-a-problem": "समस्या की रिपोर्ट करें",
"visit-website": "tea.xyz पर जाएँ",
"terms-services": "नियम और शर्तें",
"privacy-policy": "गोपनीयता नीति"
},
"documentation": {
"title": "दस्तावेज़ीकरण",
"workshops": "कार्यशालाएँ"
},
"view-all": "सभी देखें",
"sorting": {
"label": "इसके अनुसार क्रमबद्ध करें",
"popularity": "सबसे लोकप्रिय",
"most-recent": "सबसे हाल का"
},
"common": {
"home": "होम",
"all": "सभी",
"articles": "लेख",
"workshops": "कार्यशालाएँ",
"metadata": "मेटाडेटा",
"homepage": "होमपेज",
"documentation": "दस्तावेज़ीकरण",
"github-repository": "GitHub रिपॉजिटरी",
"repository": "रिपॉजिटरी",
"contributors": "योगदानकर्ता",
"view-on-github": "GITHUB पर देखें"
},
"tabs": {
"details": "pkg",
"cli": "cli",
"gui": "gui"
},
"notification": {
"update-header": "tea/gui को {{version}} में अपडेट करें?",
"gui-restarting": "जारी रखने से पूरा होने के बाद एप्लिकेशन पुनः आरंभ हो जाएगा। सुनिश्चित करें कि कोई चल रहा ऑपरेशन न हो। क्या आप जारी रखना चाहते हैं?",
"gui-restart": "पुनः आरंभ करें"
},
"side-menu-title": {
"discover": "खोजें",
"all": "सभी पैकेज",
"installed": "इंस्टॉल किए गए पैकेज",
"installed_updates_available": "अपडेट उपलब्ध",
"recently_updated": "हाल ही में अपडेट किए गए",
"new_packages": "नए पैकेज",
"popular": "लोकप्रिय",
"featured": "विशेष रूप से प्रदर्शित",
"essentials": "आवश्यक",
"starstruck": "स्टारस्ट्रक हेवीवेट्स",
"made_by_tea": "चाय द्वारा बनाया गया",
"local_packages": "स्थानीय पैकेज"
},
"tags": {
"discover": "खोजें",
"all": "सभी पैकेज",
"installed": "इंस्टॉल किए गए",
"installed_updates_available": "अपडेट उपलब्ध",
"recently_updated": "हाल ही में अपडेट किए गए",
"new_packages": "नए पैकेज",
"popular": "लोकप्रिय",
"featured": "विशेष रूप से प्रदर्शित",
"essentials": "आवश्यक",
"starstruck": "स्टारस्ट्रक",
"made_by_tea": "चाय द्वारा बनाया गया",
"local_packages": "स्थानीय पैकेज"
},
"discover": {
"featured_title": "स्थानीय AI आवश्यकताएँ",
"featured_description": "स्थानीय AI की दुनिया का अन्वेषण करें। यह आपका मंच है AutoGPT और Stable Diffusion Web UI जैसे प्रसिद्ध AI उपकरणों के साथ प्रयोग करने के लिए, सीधे आपके स्थानीय सिस्टम से। अपने AI प्रोजेक्ट्स को शुरू करें जबकि अपने डेटा को सुरक्षित और संरक्षित रखें, अपनी इच्छानुसार अनुकूलित करने की स्वतंत्रता के साथ।"
}
}
}
Loading