natintosh / intl_phone_number_input

MIT License
164 stars 496 forks source link

Any idea how we can translate countries name? #324

Closed halhwadi closed 2 years ago

halhwadi commented 2 years ago

Hello

I'm using localization package to translate text in my app, and I tried to use the same to translate countries list in phone menu, but unfortunately it doesn't work, I passed the countries 2 alpha code to countries as stated in the below code, but no country has been displayed since countries list need to be passed using 2 alpha code? and as known this code is available in English language only (at least as per me knowledge)..

Can you please advise how I can display the name of countries in different languages ?

`child: Row(
                                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                  mainAxisSize: MainAxisSize.max,
                                  children: [
                                    Expanded(
                                      child:IntlPhoneField(
                                        countries: [AppLocalizations.of(context)!.ae],
                                        initialValue: myControllerMobileNumber.text,
                                        invalidNumberMessage: AppLocalizations.of(context)!.invalidmobilenumber,
                                        textAlign : TextAlign.center,
                                        controller: myControllerMobileNumber,
                                        // initialCountryCode: 'AE',
                              decoration:InputDecoration(
                                    contentPadding: EdgeInsets.fromLTRB(0, 5.5, 0, 5.5),
                                    labelStyle: TextStyle(fontWeight: FontWeight.bold,),
                                    labelText: AppLocalizations.of(context)!.mobilenumber,
                                    enabledBorder: OutlineInputBorder(
                                        borderSide : const BorderSide(
                                          color: Colors.lightGreen,
                                          width: 2,
                                          style: BorderStyle.solid,
                                        ),
                                        borderRadius : const BorderRadius.all(Radius.circular(14.0))
                                    ),
                                    focusedBorder: OutlineInputBorder(
                                        borderSide : const BorderSide(
                                          color: Colors.green,
                                          width: 2,
                                          style: BorderStyle.solid,
                                        ),
                                        borderRadius : const BorderRadius.all(Radius.circular(14.0))
                                    ),
                                  ),
                                  validator: (value) {
                                    if (value == null) {
                                      return AppLocalizations.of(context)!.pleaseentersometext;
                                    }
                                    return null;
                                  },
                                    onTap: (){
                                          print('myControllerMobileNumber');
                                          print(myControllerMobileNumber);
                                    },
                                      )`
asashour commented 2 years ago

There is a locale parameter, which can be set to something like ar, the country_list is here.

halhwadi commented 2 years ago

Thank you Ahmad, I already have implemented the locale on my app and it works properly, All text are translated correctly except countries list in Int_phone_number menu. As I understood from your reply, that countries list in Countries class has already translation including Arabic 'ar' however countries names still displayed in English when device default language is set to Arabic.. Is there any missing configuration? Like passing the locale value to IntPhoneField, as I can't see any parameter called locale in this widget?

Best Regards

asashour commented 2 years ago

This repo is for intl_phone_number_input, which has locale parameter. If you are using IntlPhoneField, its repo is here

halhwadi commented 2 years ago

Thank you Ahmad and sorry for this mistake