mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-09 20:29:36 +02:00
Add language settings and toggle
This commit is contained in:
+2
-3
@@ -1,13 +1,13 @@
|
|||||||
import { PostProcessorModule } from 'i18next';
|
import { PostProcessorModule } from 'i18next';
|
||||||
import i18n from 'i18next';
|
import i18n from 'i18next';
|
||||||
import { initReactI18next } from 'react-i18next';
|
import { initReactI18next } from 'react-i18next';
|
||||||
const en = require('./locales/en.json');
|
import en from './locales/en.json';
|
||||||
|
|
||||||
const resources = {
|
const resources = {
|
||||||
en: { translation: en },
|
en: { translation: en },
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Languages = [
|
export const languages = [
|
||||||
{
|
{
|
||||||
label: 'English',
|
label: 'English',
|
||||||
value: 'en',
|
value: 'en',
|
||||||
@@ -66,7 +66,6 @@ i18n.use(lowerCasePostProcessor)
|
|||||||
interpolation: {
|
interpolation: {
|
||||||
escapeValue: false, // react already safes from xss
|
escapeValue: false, // react already safes from xss
|
||||||
},
|
},
|
||||||
lng: 'en',
|
|
||||||
resources,
|
resources,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import { PlayerState, usePlayerStore, useQueueControls } from '/@/renderer/store
|
|||||||
import { FontType, PlaybackType, PlayerStatus } from '/@/renderer/types';
|
import { FontType, PlaybackType, PlayerStatus } from '/@/renderer/types';
|
||||||
import '@ag-grid-community/styles/ag-grid.css';
|
import '@ag-grid-community/styles/ag-grid.css';
|
||||||
import { useDiscordRpc } from '/@/renderer/features/discord-rpc/use-discord-rpc';
|
import { useDiscordRpc } from '/@/renderer/features/discord-rpc/use-discord-rpc';
|
||||||
|
import i18n from '/@/i18n/i18n';
|
||||||
|
|
||||||
ModuleRegistry.registerModules([ClientSideRowModelModule, InfiniteRowModelModule]);
|
ModuleRegistry.registerModules([ClientSideRowModelModule, InfiniteRowModelModule]);
|
||||||
|
|
||||||
@@ -39,6 +40,7 @@ const remote = isElectron() ? window.electron.remote : null;
|
|||||||
export const App = () => {
|
export const App = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const accent = useSettingsStore((store) => store.general.accent);
|
const accent = useSettingsStore((store) => store.general.accent);
|
||||||
|
const language = useSettingsStore((store) => store.general.language);
|
||||||
const { builtIn, custom, system, type } = useSettingsStore((state) => state.font);
|
const { builtIn, custom, system, type } = useSettingsStore((state) => state.font);
|
||||||
const { type: playbackType } = usePlaybackSettings();
|
const { type: playbackType } = usePlaybackSettings();
|
||||||
const { bindings } = useHotkeySettings();
|
const { bindings } = useHotkeySettings();
|
||||||
@@ -178,6 +180,12 @@ export const App = () => {
|
|||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (language) {
|
||||||
|
i18n.changeLanguage(language);
|
||||||
|
}
|
||||||
|
}, [language]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MantineProvider
|
<MantineProvider
|
||||||
withGlobalStyles
|
withGlobalStyles
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import { FontType } from '/@/renderer/types';
|
import { FontType } from '/@/renderer/types';
|
||||||
import i18n from '/@/i18n/i18n';
|
import i18n, { languages } from '/@/i18n/i18n';
|
||||||
|
|
||||||
const localSettings = isElectron() ? window.electron.localSettings : null;
|
const localSettings = isElectron() ? window.electron.localSettings : null;
|
||||||
const ipc = isElectron() ? window.electron.ipc : null;
|
const ipc = isElectron() ? window.electron.ipc : null;
|
||||||
@@ -146,12 +146,22 @@ export const ApplicationSettings = () => {
|
|||||||
getFonts();
|
getFonts();
|
||||||
}, [fontSettings, localFonts, setSettings, t]);
|
}, [fontSettings, localFonts, setSettings, t]);
|
||||||
|
|
||||||
|
const handleChangeLanguage = (e: string) => {
|
||||||
|
setSettings({
|
||||||
|
general: {
|
||||||
|
...settings,
|
||||||
|
language: e,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const options: SettingOption[] = [
|
const options: SettingOption[] = [
|
||||||
{
|
{
|
||||||
control: (
|
control: (
|
||||||
<Select
|
<Select
|
||||||
disabled
|
data={languages}
|
||||||
data={[]}
|
value={settings.language}
|
||||||
|
onChange={handleChangeLanguage}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
description: t('setting.language', {
|
description: t('setting.language', {
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ export interface SettingsState {
|
|||||||
accent: string;
|
accent: string;
|
||||||
defaultFullPlaylist: boolean;
|
defaultFullPlaylist: boolean;
|
||||||
followSystemTheme: boolean;
|
followSystemTheme: boolean;
|
||||||
|
language: string;
|
||||||
playButtonBehavior: Play;
|
playButtonBehavior: Play;
|
||||||
resume: boolean;
|
resume: boolean;
|
||||||
showQueueDrawerButton: boolean;
|
showQueueDrawerButton: boolean;
|
||||||
@@ -282,6 +282,7 @@ const initialState: SettingsState = {
|
|||||||
accent: 'rgb(53, 116, 252)',
|
accent: 'rgb(53, 116, 252)',
|
||||||
defaultFullPlaylist: true,
|
defaultFullPlaylist: true,
|
||||||
followSystemTheme: false,
|
followSystemTheme: false,
|
||||||
|
language: 'en',
|
||||||
playButtonBehavior: Play.NOW,
|
playButtonBehavior: Play.NOW,
|
||||||
resume: false,
|
resume: false,
|
||||||
showQueueDrawerButton: false,
|
showQueueDrawerButton: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user