Skip to content

Commit

Permalink
fix(settings): not updating lang selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
eythaann committed Jan 8, 2025
1 parent 2739ee0 commit bafb914
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/apps/settings/modules/AppLauncher/infra.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function AppLauncherSettings() {
<SettingsOption>
<b>{t('app_launcher.monitor')}</b>
<Select
options={OptionsFromEnum(SeelenLauncherMonitor, 'app_launcher.launch_on')}
options={OptionsFromEnum(t, SeelenLauncherMonitor, 'app_launcher.launch_on')}
value={monitor}
onChange={onChangeMonitor}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ export function Identifier({ identifier, onChange, onRemove }: Props) {
</SettingsOption>
<SettingsOption>
<span>{t('apps_configurations.identifier.kind')}</span>
<Select value={kind} options={OptionsFromEnum(AppIdentifierType, 'apps_configurations.identifier.type')} onSelect={onSelectKind} />
<Select value={kind} options={OptionsFromEnum(t, AppIdentifierType, 'apps_configurations.identifier.type')} onSelect={onSelectKind} />
</SettingsOption>
<SettingsOption>
<span>{t('apps_configurations.identifier.matching_strategy')}</span>
<Select
value={matchingStrategy}
options={OptionsFromEnum(MatchingStrategy, 'apps_configurations.identifier.matching_strategy_option')}
options={OptionsFromEnum(t, MatchingStrategy, 'apps_configurations.identifier.matching_strategy_option')}
onSelect={onSelectMatchingStrategy}
/>
</SettingsOption>
Expand Down
2 changes: 1 addition & 1 deletion src/apps/settings/modules/fancyToolbar/infra.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function FancyToolbarSettings() {
<Select
style={{ width: '120px' }}
value={settings.hideMode}
options={OptionsFromEnum(HideMode, 'toolbar.hide_mode')}
options={OptionsFromEnum(t, HideMode, 'toolbar.hide_mode')}
onChange={(value) => dispatch(FancyToolbarActions.setHideMode(value))}
/>
</SettingsOption>
Expand Down
4 changes: 2 additions & 2 deletions src/apps/settings/modules/seelenweg/infra.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const SeelenWegSettings = () => {
<Select
style={{ width: '120px' }}
value={settings.mode}
options={OptionsFromEnum(SeelenWegMode, 'weg.mode')}
options={OptionsFromEnum(t, SeelenWegMode, 'weg.mode')}
onChange={(value) => dispatch(SeelenWegActions.setMode(value))}
/>
</SettingsOption>
Expand Down Expand Up @@ -82,7 +82,7 @@ export const SeelenWegSettings = () => {
<Select
style={{ width: '120px' }}
value={settings.hideMode}
options={OptionsFromEnum(HideMode, 'weg.hide_mode')}
options={OptionsFromEnum(t, HideMode, 'weg.hide_mode')}
onChange={(value) => dispatch(SeelenWegActions.setHideMode(value))}
/>
</SettingsOption>
Expand Down
9 changes: 5 additions & 4 deletions src/apps/settings/modules/shared/utils/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Action, Slice } from '@reduxjs/toolkit';
import { t } from 'i18next';
import { TFunction } from 'i18next';

import { HexColor, ReducersFor, SelectorsFor } from './domain';

Expand Down Expand Up @@ -60,17 +60,18 @@ export const validateHexColor = (str: string): HexColor | null => {
return str as HexColor;
};

export const OptionsFromEnum = (obj: anyObject, translationPrefix: string) =>
Object.values(obj).map((value) => ({
export const OptionsFromEnum = (t: TFunction, obj: anyObject, translationPrefix: string) => {
return Object.values(obj).map((value) => ({
label: t(translationPrefix + '.' + toSnakeCase(value)),
value,
}));
};

function toSnakeCase(text: string) {
let snake = '';
for (let i = 0; i < text.length; i++) {
const char = text[i]!;
if ((char === char.toLowerCase() && !char.match(/[0-9]/))) {
if (char === char.toLowerCase() && !char.match(/[0-9]/)) {
snake += char.toLowerCase();
} else if (i == 0) {
snake += `${char.toLowerCase()}`;
Expand Down

0 comments on commit bafb914

Please sign in to comment.