mirror of
https://github.com/mastodon/mastodon.git
synced 2025-11-29 19:03:41 +00:00
Fix initially selected language in Rules panel, hide selector when no alternative translations exist (#36672)
Some checks failed
Check i18n / check-i18n (push) Has been cancelled
Chromatic / Run Chromatic (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
CodeQL / Analyze (ruby) (push) Has been cancelled
Check formatting / lint (push) Has been cancelled
JavaScript Linting / lint (push) Has been cancelled
Ruby Linting / lint (push) Has been cancelled
JavaScript Testing / test (push) Has been cancelled
Historical data migration test / test (14-alpine) (push) Has been cancelled
Historical data migration test / test (15-alpine) (push) Has been cancelled
Historical data migration test / test (16-alpine) (push) Has been cancelled
Historical data migration test / test (17-alpine) (push) Has been cancelled
Ruby Testing / build (production) (push) Has been cancelled
Ruby Testing / build (test) (push) Has been cancelled
Ruby Testing / test (.ruby-version) (push) Has been cancelled
Ruby Testing / test (3.2) (push) Has been cancelled
Ruby Testing / test (3.3) (push) Has been cancelled
Ruby Testing / ImageMagick tests (.ruby-version) (push) Has been cancelled
Ruby Testing / ImageMagick tests (3.2) (push) Has been cancelled
Ruby Testing / ImageMagick tests (3.3) (push) Has been cancelled
Ruby Testing / End to End testing (.ruby-version) (push) Has been cancelled
Ruby Testing / End to End testing (3.2) (push) Has been cancelled
Ruby Testing / End to End testing (3.3) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Has been cancelled
Bundler Audit / security (push) Has been cancelled
Some checks failed
Check i18n / check-i18n (push) Has been cancelled
Chromatic / Run Chromatic (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
CodeQL / Analyze (ruby) (push) Has been cancelled
Check formatting / lint (push) Has been cancelled
JavaScript Linting / lint (push) Has been cancelled
Ruby Linting / lint (push) Has been cancelled
JavaScript Testing / test (push) Has been cancelled
Historical data migration test / test (14-alpine) (push) Has been cancelled
Historical data migration test / test (15-alpine) (push) Has been cancelled
Historical data migration test / test (16-alpine) (push) Has been cancelled
Historical data migration test / test (17-alpine) (push) Has been cancelled
Ruby Testing / build (production) (push) Has been cancelled
Ruby Testing / build (test) (push) Has been cancelled
Ruby Testing / test (.ruby-version) (push) Has been cancelled
Ruby Testing / test (3.2) (push) Has been cancelled
Ruby Testing / test (3.3) (push) Has been cancelled
Ruby Testing / ImageMagick tests (.ruby-version) (push) Has been cancelled
Ruby Testing / ImageMagick tests (3.2) (push) Has been cancelled
Ruby Testing / ImageMagick tests (3.3) (push) Has been cancelled
Ruby Testing / End to End testing (.ruby-version) (push) Has been cancelled
Ruby Testing / End to End testing (3.2) (push) Has been cancelled
Ruby Testing / End to End testing (3.3) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Has been cancelled
Bundler Audit / security (push) Has been cancelled
This commit is contained in:
parent
8a2826604c
commit
055f581ca5
|
|
@ -32,16 +32,38 @@ interface Rule extends BaseRule {
|
||||||
translations?: Record<string, BaseRule>;
|
translations?: Record<string, BaseRule>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getDefaultSelectedLocale(
|
||||||
|
currentUiLocale: string,
|
||||||
|
localeOptions: SelectItem[],
|
||||||
|
) {
|
||||||
|
const preciseMatch = localeOptions.find(
|
||||||
|
(option) => option.value === currentUiLocale,
|
||||||
|
);
|
||||||
|
if (preciseMatch) {
|
||||||
|
return preciseMatch.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
const partialLocale = currentUiLocale.split('-')[0];
|
||||||
|
const partialMatch = localeOptions.find(
|
||||||
|
(option) => option.value.split('-')[0] === partialLocale,
|
||||||
|
);
|
||||||
|
|
||||||
|
return partialMatch?.value ?? 'default';
|
||||||
|
}
|
||||||
|
|
||||||
export const RulesSection: FC<RulesSectionProps> = ({ isLoading = false }) => {
|
export const RulesSection: FC<RulesSectionProps> = ({ isLoading = false }) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const [locale, setLocale] = useState(intl.locale);
|
|
||||||
const rules = useAppSelector((state) => rulesSelector(state, locale));
|
|
||||||
const localeOptions = useAppSelector((state) =>
|
const localeOptions = useAppSelector((state) =>
|
||||||
localeOptionsSelector(state, intl),
|
localeOptionsSelector(state, intl),
|
||||||
);
|
);
|
||||||
|
const [selectedLocale, setSelectedLocale] = useState(() =>
|
||||||
|
getDefaultSelectedLocale(intl.locale, localeOptions),
|
||||||
|
);
|
||||||
|
const rules = useAppSelector((state) => rulesSelector(state, selectedLocale));
|
||||||
|
|
||||||
const handleLocaleChange: ChangeEventHandler<HTMLSelectElement> = useCallback(
|
const handleLocaleChange: ChangeEventHandler<HTMLSelectElement> = useCallback(
|
||||||
(e) => {
|
(e) => {
|
||||||
setLocale(e.currentTarget.value);
|
setSelectedLocale(e.currentTarget.value);
|
||||||
},
|
},
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
|
@ -74,25 +96,27 @@ export const RulesSection: FC<RulesSectionProps> = ({ isLoading = false }) => {
|
||||||
))}
|
))}
|
||||||
</ol>
|
</ol>
|
||||||
|
|
||||||
<div className='rules-languages'>
|
{localeOptions.length > 1 && (
|
||||||
<label htmlFor='language-select'>
|
<div className='rules-languages'>
|
||||||
<FormattedMessage
|
<label htmlFor='language-select'>
|
||||||
id='about.language_label'
|
<FormattedMessage
|
||||||
defaultMessage='Language'
|
id='about.language_label'
|
||||||
/>
|
defaultMessage='Language'
|
||||||
</label>
|
/>
|
||||||
<select onChange={handleLocaleChange} id='language-select'>
|
</label>
|
||||||
{localeOptions.map((option) => (
|
<select onChange={handleLocaleChange} id='language-select'>
|
||||||
<option
|
{localeOptions.map((option) => (
|
||||||
key={option.value}
|
<option
|
||||||
value={option.value}
|
key={option.value}
|
||||||
selected={option.value === locale}
|
value={option.value}
|
||||||
>
|
selected={option.value === selectedLocale}
|
||||||
{option.text}
|
>
|
||||||
</option>
|
{option.text}
|
||||||
))}
|
</option>
|
||||||
</select>
|
))}
|
||||||
</div>
|
</select>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</Section>
|
</Section>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user