Localize the homepage selector too

This commit is contained in:
infinite-persistence 2022-03-04 12:21:34 +08:00
parent 76493d48ee
commit 79978f026f
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0

View file

@ -1,8 +1,6 @@
// @flow // @flow
import React from 'react'; import React from 'react';
// $FlowFixMe import { getLanguageName } from 'constants/languages';
import homepages from 'homepages';
import { getLanguageEngName } from 'constants/languages';
import { FormField } from 'component/common/form'; import { FormField } from 'component/common/form';
import { getDefaultHomepageKey } from 'util/default-languages'; import { getDefaultHomepageKey } from 'util/default-languages';
@ -13,14 +11,18 @@ type Props = {
function SelectHomepage(props: Props) { function SelectHomepage(props: Props) {
const { homepage, setHomepage } = props; const { homepage, setHomepage } = props;
const homepages = window.homepages || {};
const homepageKeys = Object.keys(homepages);
function handleSetHomepage(e) { function handleSetHomepage(e) {
const { value } = e.target; const { value } = e.target;
setHomepage(value); setHomepage(value);
} }
if (Object.keys(homepages).length <= 1) {
if (homepageKeys.length <= 1) {
return null; return null;
} }
return ( return (
<React.Fragment> <React.Fragment>
<FormField <FormField
@ -29,9 +31,9 @@ function SelectHomepage(props: Props) {
onChange={handleSetHomepage} onChange={handleSetHomepage}
value={homepage || getDefaultHomepageKey()} value={homepage || getDefaultHomepageKey()}
> >
{Object.keys(homepages).map((hp) => ( {homepageKeys.map((hp) => (
<option key={'hp' + hp} value={hp}> <option key={'hp' + hp} value={hp}>
{`${getLanguageEngName(hp)}`} {getLanguageName(hp)}
</option> </option>
))} ))}
</FormField> </FormField>