jackocnr / intl-tel-input

A JavaScript plugin for entering and validating international telephone numbers
https://intl-tel-input.com
MIT License
7.54k stars 1.94k forks source link

Proposal: include translations #1567

Closed jackocnr closed 4 months ago

jackocnr commented 4 months ago

It would be helpful to include the translations for all of the country names (as well as the other 7 strings handled by the i18n option - see readme) in a few of the most popular languages, to save developers having to source the translations for themselves every time.

These could be stored as individual ES Module files e.g. for German:

// i18n/de.mjs
export default {
    fr: "Frankreich",
    de: "Deutschland",
    es: "Spanien",
    it: "Italien",
    ch: "Schweiz",
    nl: "Niederlande",
    at: "Österreich",
    dk: "Dänemark",
    // ...
    selectedCountryAriaLabel: "Ausgewähltes Land",
    noCountrySelected: "Kein Land ausgewählt",
    countryListAriaLabel: "Liste der Länder",
    searchPlaceholder: "Suchen",
    zeroSearchResults: "Keine Suchergebnisse",
    oneSearchResult: "1 Suchergebnis",
    multipleSearchResults: "${count} Suchergebnisse",
  };

These files can then be imported and then passed in via the i18n initialisation option e.g. something like this:

import intlTelInput from "intl-tel-input";
import de from "intl-tel-input/i18n/de";

intlTelInput(input, { i18n: de });

We wouldn't need to be comprehensive to begin with - one option would be to literally start with just a single language, and then build from there. I'm guessing at least the country name translations should be easy to come by - there must be repos out there containing this info already.

cc: @anthony0030 in case you have any time/interest in this, perhaps starting with Greek? 😉

anthony0030 commented 4 months ago

Hello again my friend (@jackocnr) 😃

I am happy to help with this feature. I have it working but I will need some help with the documentation and the imports/exports to make them cleaner.

if you add a translation file to src/i18n it will make the rest of the needed files.

I will make a pull request but it needs more review, docs, and improvements.

anthony0030 commented 4 months ago

Some notes/questions.

The reason the interface and countries are split: It allows you to just localize the interface while still leaving the country names in English.

Should we hard code the translation files in the src or import them like I am doing now?

Do you think it is worth making a translation file that has each country in the most common language of that country? This might cause conflicts in places that have multiple languages.

looking forward to hearing back from you.

jackocnr commented 4 months ago

Released in v21.2.0