react-native-dropdown-picker icon indicating copy to clipboard operation
react-native-dropdown-picker copied to clipboard

Adding translation to labels of dropdown

Open monabeeltahir opened this issue 2 years ago • 5 comments

Hello!

I am trying to add multi language support in dropdown menu. In my home screen I have change language button but I am finding it difficult to change the language for the dropdown menu labels

monabeeltahir avatar Mar 06 '23 18:03 monabeeltahir

Hi, You should map labels manually.

hossein-zare avatar Mar 09 '23 19:03 hossein-zare

So this is how I define the labels. The issue with this approach is that it only renders or defines labels once. const [items, setItems] = useState([ {label: strings.food, value: 'Food'}, {label: 'Dental', value: 'Dental'}, {label: strings.medical, value: 'Medical'}, {label: strings.housing, value: 'Housing'}, {label: strings.womenhealth, value: 'Women'} ]);

monabeeltahir avatar Mar 09 '23 19:03 monabeeltahir

I am using 'react-localization' library and declaring the strings with translations.

monabeeltahir avatar Mar 09 '23 19:03 monabeeltahir

Try this method:

const [items, setItems] = useState([]);

useEffect(() => {
  setItems([
    {label: strings.food, value: 'Food'},
    {label: 'Dental', value: 'Dental'},
    {label: strings.medical, value: 'Medical'},
    {label: strings.housing, value: 'Housing'},
    {label: strings.womenhealth, value: 'Women'},
  ]);
}, [strings]);

hossein-zare avatar Mar 09 '23 19:03 hossein-zare

Thanks.

monabeeltahir avatar Mar 09 '23 19:03 monabeeltahir