Skip to content

Commit 830e48f

Browse files
committed
GH-35: Implement localization support
1 parent 2336d5e commit 830e48f

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

development/src/ant-phone/index.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ const PhoneInput = forwardRef(({
4545
onlyCountries = [],
4646
excludeCountries = [],
4747
preferredCountries = [],
48-
searchNotFound = "No country found",
49-
searchPlaceholder = "Search country",
5048
dropdownRender = (node) => node,
5149
onMount: handleMount = () => null,
5250
onInput: handleInput = () => null,
@@ -55,6 +53,7 @@ const PhoneInput = forwardRef(({
5553
...antInputProps
5654
}: PhoneInputProps, forwardedRef: any) => {
5755
const formInstance = useFormInstance();
56+
const {locale = {}} = useContext(ConfigContext);
5857
const formContext = useContext(FormContext);
5958
const {getPrefixCls} = useContext(ConfigContext);
6059
const inputRef = useRef<any>(null);
@@ -65,6 +64,12 @@ const PhoneInput = forwardRef(({
6564
const [minWidth, setMinWidth] = useState<number>(0);
6665
const [countryCode, setCountryCode] = useState<string>(country);
6766

67+
const {
68+
searchNotFound = "No country found",
69+
searchPlaceholder = "Search country",
70+
countries = new Proxy({}, ({get: (_: any, prop: any) => prop})),
71+
} = (locale as any).PhoneInput || {};
72+
6873
const prefixCls = getPrefixCls();
6974
injectMergedStyles(prefixCls);
7075

@@ -222,13 +227,13 @@ const PhoneInput = forwardRef(({
222227
label={<div className={`flag ${iso}`}/>}
223228
children={<div className={`${prefixCls}-phone-input-select-item`}>
224229
<div className={`flag ${iso}`}/>
225-
{name}&nbsp;{displayFormat(mask)}
230+
{countries[name]}&nbsp;{displayFormat(mask)}
226231
</div>}
227232
/>
228233
)
229234
})}
230235
</Select>
231-
), [selectValue, query, disabled, disableParentheses, disableDropdown, onDropdownVisibleChange, minWidth, searchNotFound, countriesList, setFieldValue, setValue, prefixCls, enableSearch, searchPlaceholder])
236+
), [selectValue, query, disabled, disableParentheses, disableDropdown, onDropdownVisibleChange, minWidth, searchNotFound, countries, countriesList, setFieldValue, setValue, prefixCls, enableSearch, searchPlaceholder])
232237

233238
return (
234239
<div className={`${prefixCls}-phone-input-wrapper`}

development/src/mui-phone/index.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22

33
import {ChangeEvent, forwardRef, KeyboardEvent, useCallback, useEffect, useMemo, useRef, useState} from "react";
4-
import {InputAdornment, MenuItem, Select, TextField} from "@mui/material";
4+
import {InputAdornment, MenuItem, Select, TextField, useThemeProps} from "@mui/material";
55

66
import {
77
checkValidity,
@@ -33,8 +33,6 @@ const PhoneInput = forwardRef(({
3333
onlyCountries = [],
3434
excludeCountries = [],
3535
preferredCountries = [],
36-
searchNotFound = "No country found",
37-
searchPlaceholder = "Search country",
3836
onMount: handleMount = () => null,
3937
onInput: handleInput = () => null,
4038
onChange: handleChange = () => null,
@@ -50,6 +48,12 @@ const PhoneInput = forwardRef(({
5048
const [maxWidth, setMaxWidth] = useState<number>(0);
5149
const [countryCode, setCountryCode] = useState<string>(country);
5250

51+
const {
52+
searchNotFound = "No country found",
53+
searchPlaceholder = "Search country",
54+
countries = new Proxy({}, ({get: (_: any, prop: any) => prop})),
55+
} = useThemeProps({props: {}, name: "MuiPhoneInput"}) as any;
56+
5357
const {
5458
value,
5559
pattern,
@@ -171,7 +175,7 @@ const PhoneInput = forwardRef(({
171175
children={<div className="mui-phone-input-select-item">
172176
<div className={`flag ${iso}`}/>
173177
<div className="label">
174-
{name}&nbsp;{displayFormat(mask)}
178+
{countries[name]}&nbsp;{displayFormat(mask)}
175179
</div>
176180
</div>}
177181
/>

0 commit comments

Comments
 (0)