Fix about page error when selecting non-default Rules language (#39267)

This commit is contained in:
diondiondion 2026-06-03 15:21:38 +02:00 committed by GitHub
parent 0172d819f7
commit 0ff2c7aedc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,6 +6,7 @@ import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
import { createSelector } from '@reduxjs/toolkit'; import { createSelector } from '@reduxjs/toolkit';
import type { ApiRuleJSON } from '@/mastodon/api_types/instance';
import type { SelectItem } from '@/mastodon/components/dropdown_selector'; import type { SelectItem } from '@/mastodon/components/dropdown_selector';
import { Select } from '@/mastodon/components/form_fields'; import { Select } from '@/mastodon/components/form_fields';
import type { RootState } from '@/mastodon/store'; import type { RootState } from '@/mastodon/store';
@ -104,13 +105,13 @@ export const RulesSection: FC<RulesSectionProps> = ({ isLoading = false }) => {
defaultMessage='Language' defaultMessage='Language'
/> />
</label> </label>
<Select onChange={handleLocaleChange} id='language-select'> <Select
onChange={handleLocaleChange}
id='language-select'
value={selectedLocale}
>
{localeOptions.map((option) => ( {localeOptions.map((option) => (
<option <option key={option.value} value={option.value}>
key={option.value}
value={option.value}
selected={option.value === selectedLocale}
>
{option.text} {option.text}
</option> </option>
))} ))}
@ -121,15 +122,10 @@ export const RulesSection: FC<RulesSectionProps> = ({ isLoading = false }) => {
); );
}; };
const selectRules = (state: RootState) => { const selectRules = createSelector(
const rules = state.server.server.item?.rules; [(state: RootState) => state.server.server.item],
(item) => item?.rules ?? [],
if (!rules) { );
return [];
}
return rules;
};
const rulesSelector = createSelector( const rulesSelector = createSelector(
[selectRules, (_state, locale: string) => locale], [selectRules, (_state, locale: string) => locale],
@ -142,18 +138,19 @@ const rulesSelector = createSelector(
return rule; return rule;
} }
const translatedRule: ApiRuleJSON = { ...rule };
const partialLocale = locale.split('-')[0]; const partialLocale = locale.split('-')[0];
if (partialLocale && translations[partialLocale]) { if (partialLocale && translations[partialLocale]) {
rule.text = translations[partialLocale].text; translatedRule.text = translations[partialLocale].text;
rule.hint = translations[partialLocale].hint; translatedRule.hint = translations[partialLocale].hint;
} }
if (translations[locale]) { if (translations[locale]) {
rule.text = translations[locale].text; translatedRule.text = translations[locale].text;
rule.hint = translations[locale].hint; translatedRule.hint = translations[locale].hint;
} }
return rule; return translatedRule;
}); });
}, },
); );