jackocnr / intl-tel-input

A JavaScript plugin for entering and validating international telephone numbers. React and Vue components also included.
https://intl-tel-input.com
MIT License
7.69k stars 1.95k forks source link

getCountryCode() static method with i18n #1837

Closed bertenbobje closed 1 month ago

bertenbobje commented 1 month ago

Plugin version

v24.5.1

Issue

Not really an issue per se but a feature request:

Is it an idea to be able to provide i18n data to the static methods?

f.e. (using Vue 3)

import intlTelInput from 'intl-tel-input'
import { nl } from 'intl-tel-input/i18n'

const countryDataInDutch = intlTelInput.getCountryData({ i18n: nl })

Which then would return:

[..., {
  name: "Nederland",
  iso2: "nl",
  dialCode: "31"
}, ...]

Reason being that I don't initialize an HTML Input Element in my code, I just need the country ISO2 code and their name, but the name should be translated.

jackocnr commented 1 month ago

I just need the country ISO2 code and their name, but the name should be translated.

You should be able to get this directly from the translation files - if you import the country names specifically e.g.

import nl from "intl-tel-input/build/js/i18n/nl/countries";

That will give you the contents of this file which is a list of every country name, translated into NL language, indexed by iso2 code.

Is that what you need?

bertenbobje commented 1 month ago

That is exactly what I need, thanks!