Skip to content

Commit

Permalink
Merge pull request #930 from hydralauncher/feat/refactor-languages
Browse files Browse the repository at this point in the history
feat: refactor languages
  • Loading branch information
zamitto authored Sep 9, 2024
2 parents 02907d8 + dc4aa0f commit ebb17ea
Show file tree
Hide file tree
Showing 29 changed files with 172 additions and 57 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"knex:migrate:make": "knex --knexfile src/main/knexfile.ts migrate:make --esm"
},
"dependencies": {
"@cospired/i18n-iso-languages": "^4.2.0",
"@electron-toolkit/preload": "^3.0.0",
"@electron-toolkit/utils": "^3.0.0",
"@fontsource/noto-sans": "^5.0.22",
Expand All @@ -43,7 +42,7 @@
"@vanilla-extract/dynamic": "^2.1.1",
"@vanilla-extract/recipes": "^0.5.2",
"auto-launch": "^5.0.6",
"axios": "^1.6.8",
"axios": "^1.7.7",
"better-sqlite3": "^11.2.1",
"check-disk-space": "^3.4.0",
"classnames": "^2.5.1",
Expand All @@ -59,7 +58,6 @@
"i18next": "^23.11.2",
"i18next-browser-languagedetector": "^7.2.1",
"icojs": "^0.19.3",
"iso-639-1": "3.1.2",
"jsdom": "^24.0.0",
"jsonwebtoken": "^9.0.2",
"knex": "^3.1.0",
Expand Down
1 change: 1 addition & 0 deletions src/locales/ar/translation.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"language_name": "اَلْعَرَبِيَّةُ",
"home": {
"featured": "مميّز",
"trending": "شائع",
Expand Down
1 change: 1 addition & 0 deletions src/locales/be/translation.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"language_name": "беларуская мова",
"home": {
"featured": "Рэкамэндаванае",
"trending": "Актуальнае",
Expand Down
1 change: 1 addition & 0 deletions src/locales/ca/translation.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"language_name": "Català",
"app": {
"successfully_signed_in": "Has entrat correctament"
},
Expand Down
1 change: 1 addition & 0 deletions src/locales/da/translation.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"language_name": "Dansk",
"home": {
"featured": "Anbefalet",
"trending": "Trender",
Expand Down
1 change: 1 addition & 0 deletions src/locales/en/translation.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"language_name": "English",
"app": {
"successfully_signed_in": "Successfully signed in"
},
Expand Down
1 change: 1 addition & 0 deletions src/locales/es/translation.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"language_name": "Español",
"app": {
"successfully_signed_in": "Sesión iniciada correctamente"
},
Expand Down
1 change: 1 addition & 0 deletions src/locales/fa/translation.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"language_name": "فارسی",
"home": {
"featured": "پیشنهادی",
"trending": "پرطرفدار",
Expand Down
1 change: 1 addition & 0 deletions src/locales/fr/translation.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"language_name": "Français",
"home": {
"featured": "En vedette",
"trending": "Tendance",
Expand Down
1 change: 1 addition & 0 deletions src/locales/hu/translation.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"language_name": "Magyar",
"home": {
"featured": "Featured",
"trending": "Népszerű",
Expand Down
1 change: 1 addition & 0 deletions src/locales/id/translation.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"language_name": "Bahasa Indonesia",
"app": {
"successfully_signed_in": "Berhasil masuk"
},
Expand Down
69 changes: 47 additions & 22 deletions src/locales/index.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,47 @@
export { default as en } from "./en/translation.json";
export { default as ptPT } from "./pt-PT/translation.json";
export { default as ptBR } from "./pt-BR/translation.json";
export { default as es } from "./es/translation.json";
export { default as nl } from "./nl/translation.json";
export { default as fr } from "./fr/translation.json";
export { default as hu } from "./hu/translation.json";
export { default as it } from "./it/translation.json";
export { default as pl } from "./pl/translation.json";
export { default as ru } from "./ru/translation.json";
export { default as tr } from "./tr/translation.json";
export { default as be } from "./be/translation.json";
export { default as uk } from "./uk/translation.json";
export { default as zh } from "./zh/translation.json";
export { default as id } from "./id/translation.json";
export { default as ko } from "./ko/translation.json";
export { default as da } from "./da/translation.json";
export { default as ar } from "./ar/translation.json";
export { default as fa } from "./fa/translation.json";
export { default as ro } from "./ro/translation.json";
export { default as ca } from "./ca/translation.json";
export { default as kk } from "./kk/translation.json";
import en from "./en/translation.json";
import ptPT from "./pt-PT/translation.json";
import ptBR from "./pt-BR/translation.json";
import es from "./es/translation.json";
import nl from "./nl/translation.json";
import fr from "./fr/translation.json";
import hu from "./hu/translation.json";
import it from "./it/translation.json";
import pl from "./pl/translation.json";
import ru from "./ru/translation.json";
import tr from "./tr/translation.json";
import be from "./be/translation.json";
import uk from "./uk/translation.json";
import zh from "./zh/translation.json";
import id from "./id/translation.json";
import ko from "./ko/translation.json";
import da from "./da/translation.json";
import ar from "./ar/translation.json";
import fa from "./fa/translation.json";
import ro from "./ro/translation.json";
import ca from "./ca/translation.json";
import kk from "./kk/translation.json";

export default {
"pt-BR": ptBR,
"pt-PT": ptPT,
en,
es,
nl,
fr,
hu,
it,
pl,
ru,
tr,
be,
uk,
zh,
id,
ko,
da,
ar,
fa,
ro,
ca,
kk,
};
1 change: 1 addition & 0 deletions src/locales/it/translation.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"language_name": "Italiano",
"home": {
"featured": "In primo piano",
"trending": "Di tendenza",
Expand Down
1 change: 1 addition & 0 deletions src/locales/kk/translation.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"language_name": "қазақ тілі",
"app": {
"successfully_signed_in": "Сәтті кіру"
},
Expand Down
1 change: 1 addition & 0 deletions src/locales/ko/translation.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"language_name": "한국어",
"home": {
"featured": "추천",
"trending": "인기",
Expand Down
1 change: 1 addition & 0 deletions src/locales/nl/translation.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"language_name": "Nederlands",
"home": {
"featured": "Uitgelicht",
"trending": "Trending",
Expand Down
1 change: 1 addition & 0 deletions src/locales/pl/translation.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"language_name": "Polski",
"home": {
"featured": "Wyróżnione",
"trending": "Trendujące",
Expand Down
1 change: 1 addition & 0 deletions src/locales/pt-BR/translation.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"language_name": "Português (Brasil)",
"app": {
"successfully_signed_in": "Autenticado com sucesso"
},
Expand Down
1 change: 1 addition & 0 deletions src/locales/pt-PT/translation.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"language_name": "Português (Portugal)",
"app": {
"successfully_signed_in": "Sessão iniciada com sucesso"
},
Expand Down
1 change: 1 addition & 0 deletions src/locales/ro/translation.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"language_name": "Română",
"home": {
"featured": "Recomandate",
"trending": "Populare",
Expand Down
1 change: 1 addition & 0 deletions src/locales/ru/translation.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"language_name": "Русский",
"app": {
"successfully_signed_in": "Успешный вход"
},
Expand Down
1 change: 1 addition & 0 deletions src/locales/tr/translation.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"language_name": "Türkçe",
"home": {
"featured": "Öne çıkan",
"trending": "Popüler",
Expand Down
1 change: 1 addition & 0 deletions src/locales/uk/translation.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"language_name": "Українська",
"app": {
"successfully_signed_in": "Успішний вхід в систему"
},
Expand Down
1 change: 1 addition & 0 deletions src/locales/zh/translation.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"language_name": "中文",
"app": {
"successfully_signed_in": "已成功登录"
},
Expand Down
Binary file removed src/main/hydra.dev.db
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import url from "node:url";
import { electronApp, optimizer } from "@electron-toolkit/utils";
import { logger, PythonInstance, WindowManager } from "@main/services";
import { dataSource } from "@main/data-source";
import * as resources from "@locales";
import resources from "@locales";
import { userPreferencesRepository } from "@main/repository";
import { knexClient, migrationConfig } from "./knex-client";

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {

import { store } from "./store";

import * as resources from "@locales";
import resources from "@locales";
import { User } from "./pages/user/user";

Sentry.init({});
Expand Down
24 changes: 4 additions & 20 deletions src/renderer/src/pages/settings/settings-general.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import { useContext, useEffect, useState } from "react";
import languages from "@cospired/i18n-iso-languages";
import languagesEn from "@cospired/i18n-iso-languages/langs/en.json";

import {
TextField,
Button,
CheckboxField,
SelectField,
} from "@renderer/components";
import { useTranslation } from "react-i18next";

import { useAppSelector } from "@renderer/hooks";

import { changeLanguage } from "i18next";
import * as languageResources from "@locales";
import languageResources from "@locales";
import { orderBy } from "lodash-es";
import { settingsContext } from "@renderer/context";

Expand All @@ -22,13 +17,6 @@ interface LanguageOption {
nativeName: string;
}

languages.registerLocale(languagesEn);

const customLanguageNames = {
ptBR: "Português (Brasil)",
ptPT: "Português (Portugal)",
};

export function SettingsGeneral() {
const { t } = useTranslation("settings");

Expand Down Expand Up @@ -58,11 +46,9 @@ export function SettingsGeneral() {

setLanguageOptions(
orderBy(
Object.keys(languageResources).map((language) => {
Object.entries(languageResources).map(([language, value]) => {
return {
nativeName:
customLanguageNames[language] ||
languages.getName(language, "en"),
nativeName: value.language_name,
option: language,
};
}),
Expand Down Expand Up @@ -103,16 +89,14 @@ export function SettingsGeneral() {

function updateFormWithUserPreferences() {
if (userPreferences) {
const parsedLanguage = userPreferences.language;

setForm((prev) => ({
...prev,
downloadsPath: userPreferences.downloadsPath ?? defaultDownloadsPath,
downloadNotificationsEnabled:
userPreferences.downloadNotificationsEnabled,
repackUpdatesNotificationsEnabled:
userPreferences.repackUpdatesNotificationsEnabled,
language: parsedLanguage,
language: userPreferences.language,
}));
}
}
Expand Down
Loading

0 comments on commit ebb17ea

Please sign in to comment.