jackocnr / intl-tel-input

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

French Translation #191

Closed harold-s closed 9 years ago

harold-s commented 9 years ago

Hello,

Your library is great and works very well !

However, I need to make it work on a French websites and need the country names displayed in French.

I have found in other issues this function : $.fn.intlTelInput.setCountryData(allCountries);

But this function does not seem to be in the source code anymore ?

How can I translate allCountries ? Do you plan to support locales ?

If you do have some plans, I have developped a ruby script (https://github.com/harold-s/harold-s/blob/master/intl-tel-input-french-translation/intl-tel-input-french-translation.rb) that generates a French translation of allCountries based on your Array and replaces the name of the country from a list I have found on a website (http://www.buddyweb.fr/extensions/, ISO 3166-1 alpha-2) and intelligently keeps the English name in brackets and deletes the French name in brackets.

I have tested and verifies the output list which seems correct. You can see the result here : https://github.com/harold-s/harold-s/blob/master/intl-tel-input-french-translation/result.json

You can obviously re-use my work for the French translation ! If someone wants to translate another language, he may re-adapt my ruby script (it only needs a hash table with country code as keys and country name as values)

EDIT : See last post if you look for a French translation !

jackocnr commented 9 years ago

Hi Harold,

You just need to use getCountryData and then modify that data. See the example here.

Thanks for posting links to your work - I hope they will be helpful to others!

Let me know if you have any other questions.

harold-s commented 9 years ago

Just as a follow up if someone needs to translate in French, I have updated this issue's title and I have updated my script and documented a bit: https://github.com/harold-s/harold-s/tree/master/intl-tel-input-french-translation

If you want a French translation prepend on your script :

var countryData = $.fn.intlTelInput.getCountryData();
var hashCountryDataTranslation = {"af":"Afghanistan (‫افغانستان‬‎)","al":"Albanie (Shqipëri)","dz":"Algérie (‫الجزائر‬‎)","as":"Samoa américaines (American Samoa)","ad":"Andorre (Andorra)","ao":"Angola","ai":"Anguilla","ag":"Antigua-et-Barbuda (Antigua and Barbuda)","ar":"Argentine (Argentina)","am":"Arménie (Հայաստան)","aw":"Aruba","au":"Australie (Australia)","at":"Autriche (Österreich)","az":"Azerbaïdjan (Azərbaycan)","bs":"Bahamas","bh":"Bahreïn (‫البحرين‬‎)","bd":"Bangladesh (বাংলাদেশ)","bb":"Barbade (Barbados)","by":"Biélorussie (Беларусь)","be":"Belgique (België)","bz":"Belize","bj":"Bénin","bm":"Bermudes (Bermuda)","bt":"Bhoutan (འབྲུག)","bo":"Bolivie (Bolivia)","ba":"Bosnie-Herzégovine (Босна и Херцеговина)","bw":"Botswana","br":"Brésil (Brasil)","io":"Territoire britannique de l’océan Indien (British Indian Ocean Territory)","vg":"Îles Vierges britanniques (British Virgin Islands)","bn":"Brunei","bg":"Bulgarie (България)","bf":"Burkina Faso","bi":"Burundi (Uburundi)","kh":"Cambodge (កម្ពុជា)","cm":"Cameroun","ca":"Canada","cv":"Cap-Vert (Kabu Verdi)","bq":"Bonaire, Saint-Eustache et Saba (Caribbean Netherlands)","ky":"Îles Caïmans (Cay Islands)","cf":"République centrafricaine","td":"Tchad","cl":"Chili (Chile)","cn":"Chine (中国)","co":"Colombie (Colombia)","km":"Comores (‫جزر القمر‬‎)","cd":"République démocratique du Congo (Jamhuri ya Kidemokrasia ya Kongo)","cg":"République du Congo / (Congo) (Congo-Brazzaville)","ck":"Îles Cook (Cook Islands)","cr":"Costa Rica","ci":"Côte d’Ivoire","hr":"Croatie (Hrvatska)","cu":"Cuba","cw":"Curaçao","cy":"Chypre (Κύπρος)","cz":"République tchèque (Česká republika)","dk":"Danemark (Danmark)","dj":"Djibouti","dm":"Dominique (Dominica)","do":"République dominicaine (República Dominicana)","ec":"Équateur (Ecuador)","eg":"Égypte (‫مصر‬‎)","sv":"Salvador (El Salvador)","gq":"Guinée équatoriale (Guinea Ecuatorial)","er":"Érythrée (Eritrea)","ee":"Estonie (Eesti)","et":"Éthiopie (Ethiopia)","fk":"Îles Malouines (Islas Malvinas)","fo":"Îles Féroé (Føroyar)","fj":"Fidji (Fiji)","fi":"Finlande (Suomi)","fr":"France","gf":"Guyane (Guyane française)","pf":"Polynésie française","ga":"Gabon","gm":"Gambie (Gambia)","ge":"Géorgie (საქართველო)","de":"Allemagne (Deutschland)","gh":"Ghana (Gaana)","gi":"Gibraltar","gr":"Grèce (Ελλάδα)","gl":"Groenland (Kalaallit Nunaat)","gd":"Grenade (Grenada)","gp":"Guadeloupe","gu":"Guam","gt":"Guatemala","gn":"Guinée","gw":"Guinée-Bissau (República da Guiné-Bissau)","gy":"Guyana","ht":"Haïti (Haiti)","hn":"Honduras","hk":"Hong Kong (香港)","hu":"Hongrie (Magyarország)","is":"Islande (Ísland)","in":"Inde (भारत)","id":"Indonésie (Indonesia)","ir":"Iran (‫ایران‬‎)","iq":"Irak (‫العراق‬‎)","ie":"Irlande (Ireland)","il":"Israël (‫ישראל‬‎)","it":"Italie (Italia)","jm":"Jamaïque (Jamaica)","jp":"Japon (日本)","jo":"Jordanie (‫الأردن‬‎)","kz":"Kazakhstan (Казахстан)","ke":"Kenya","ki":"Kiribati","kw":"Koweït (‫الكويت‬‎)","kg":"Kirghizistan (Кыргызстан)","la":"Laos (ລາວ)","lv":"Lettonie (Latvija)","lb":"Liban (‫لبنان‬‎)","ls":"Lesotho","lr":"Liberia","ly":"Libye (‫ليبيا‬‎)","li":"Liechtenstein","lt":"Lituanie (Lietuva)","lu":"Luxembourg","mo":"Macao (澳門)","mk":"Macédoine (Македонија)","mg":"Madagascar (Madagasikara)","mw":"Malawi","my":"Malaisie (Malaysia)","mv":"Maldives","ml":"Mali","mt":"Malte (Malta)","mh":"Marshall (Marshall Islands)","mq":"Martinique","mr":"Mauritanie (‫موريتانيا‬‎)","mu":"Maurice (Moris)","mx":"Mexique (México)","fm":"Micronésie (Micronesia)","md":"Moldavie (Republica Moldova)","mc":"Monaco","mn":"Mongolie (Монгол)","me":"Monténégro (Crna Gora)","ms":"Montserrat","ma":"Maroc (‫المغرب‬‎)","mz":"Mozambique (Moçambique)","mm":"Birmanie (မြန်မာ)","na":"Namibie (Namibië)","nr":"Nauru","np":"Népal (नेपाल)","nl":"Pays-Bas (Nederland)","nc":"Nouvelle-Calédonie","nz":"Nouvelle-Zélande (New Zealand)","ni":"Nicaragua","ne":"Niger (Nijar)","ng":"Nigeria","nu":"Niue","nf":"Île Norfolk (Norfolk Island)","kp":"Corée du Nord (조선 민주주의 인민 공화국)","mp":"Îles Mariannes du Nord (Northern Mariana Islands)","no":"Norvège (Norge)","om":"Oman (‫عُمان‬‎)","pk":"Pakistan (‫پاکستان‬‎)","pw":"Palaos (Palau)","ps":"Autorité palestinienne (‫فلسطين‬‎)","pa":"Panama (Panamá)","pg":"Papouasie-Nouvelle-Guinée (Papua New Guinea)","py":"Paraguay","pe":"Pérou (Perú)","ph":"Philippines","pl":"Pologne (Polska)","pt":"Portugal","pr":"Porto Rico (Puerto Rico)","qa":"Qatar (‫قطر‬‎)","re":"La Réunion","ro":"Roumanie (România)","ru":"Russie (Россия)","rw":"Rwanda","bl":"Saint-Barthélemy","sh":"Sainte-Hélène, Ascension et Tristan da Cunha (Saint Helena)","kn":"Saint-Christophe-et-Niévès (Saint Kitts and Nevis)","lc":"Sainte-Lucie (Saint Lucia)","mf":"Saint-Martin (Antilles françaises) (partie française))","pm":"Saint-Pierre-et-Miquelon","vc":"Saint-Vincent-et-les-Grenadines (Saint Vincent and the Grenadines)","ws":"Samoa","sm":"Saint-Marin (San Marino)","st":"Sao Tomé-et-Principe (São Tomé e Príncipe)","sa":"Arabie saoudite (‫المملكة العربية السعودية‬‎)","sn":"Sénégal","rs":"Serbie (Србија)","sc":"Seychelles","sl":"Sierra Leone","sg":"Singapour (Singapore)","sx":"Saint-Martin (Sint Maarten)","sk":"Slovaquie (Slovensko)","si":"Slovénie (Slovenija)","sb":"Salomon (Solomon Islands)","so":"Somalie (Soomaaliya)","za":"Afrique du Sud (South Africa)","kr":"Corée du Sud (대한민국)","ss":"Soudan du Sud (‫جنوب السودان‬‎)","es":"Espagne (España)","lk":"Sri Lanka (ශ්‍රී ලංකාව)","sd":"Soudan (‫السودان‬‎)","sr":"Suriname","sz":"Swaziland","se":"Suède (Sverige)","ch":"Suisse (Schweiz)","sy":"Syrie (‫سوريا‬‎)","tw":"Taïwan / (République de Chine (Taïwan)) (台灣)","tj":"Tadjikistan (Tajikistan)","tz":"Tanzanie (Tanzania)","th":"Thaïlande (ไทย)","tl":"Timor oriental (Timor-Leste)","tg":"Togo","tk":"Tokelau","to":"Tonga","tt":"Trinité-et-Tobago (Trinidad and Tobago)","tn":"Tunisie (‫تونس‬‎)","tr":"Turquie (Türkiye)","tm":"Turkménistan (Turkmenistan)","tc":"Îles Turques-et-Caïques (Turks and Caicos Islands)","tv":"Tuvalu","vi":"Îles Vierges des États-Unis (U.S. Virgin Islands)","ug":"Ouganda (Uganda)","ua":"Ukraine (Україна)","ae":"Émirats arabes unis (‫الإمارات العربية المتحدة‬‎)","gb":"Royaume-Uni (United Kingdom)","us":"États-Unis (United States)","uy":"Uruguay","uz":"Ouzbékistan (Oʻzbekiston)","vu":"Vanuatu","va":"État de la Cité du Vatican (Città del Vaticano)","ve":"Venezuela","vn":"Viêt Nam (Việt Nam)","wf":"Wallis-et-Futuna (Wallis and Futuna)","ye":"Yémen (‫اليمن‬‎)","zm":"Zambie (Zambia)","zw":"Zimbabwe"};
$.each(countryData, function(i, country) {
  country.name = hashCountryDataTranslation[country.iso2];
});

Working examples may be found here :

jackocnr commented 9 years ago

This is super cool! Thank you!

harold-s commented 9 years ago

Your project is really cool and works great ! Credit is to you ! Yet I still think you should create an internationalisation system with a locale that could be added to the parameters of intlTelInput which will force the download of a language JS or any other mechanism !

jackocnr commented 9 years ago

I think the best way to go about this would be to add a grunt task which automatically translates the data.js file, and outputs a full plugin build for each language, so you'd end up with build/js/intlTelInput.js and build/js/internationalization/intlTelInput-fr.js etc.

michaelrimbach commented 9 years ago

We have a german and spanish translation. (but with the "old" translation style)

Michael Rimbach michael.rimbach@gmail.com Bibergerstr. 13b, 82008 Unterhaching

2015-03-30 18:50 GMT+02:00 jackocnr notifications@github.com:

I think the best way to go about this would be to add a grunt task which automatically translates the data.js file, and outputs a full plugin build for each language, so you'd end up with build/js/intlTelInput.js and build/js/internationalization/intlTelInput-fr.js etc.

— Reply to this email directly or view it on GitHub https://github.com/Bluefieldscom/intl-tel-input/issues/191#issuecomment-87747426 .

fabdbt commented 9 years ago

Hey guys,

We spoke with @harold-s and we decided to create a ruby gem, https://github.com/SeniorMedia/intl_phone_picker , inspired from intl-tel-input-rails (@ispyropoulos) which set by default all tel fields from project to "intl-tel-input"s. We added the option "_[country_shortname]" to set the default language when importing javascript file.

For moment, only US (default language took from initial project) and french one are supported.

The goal of the next version is to use the .yml files from "config/locales" to set the country names. For moment, this is just a duplication which has for goal to ask contributions. We just compile it in JSON and add it into our javascript script.

This is a super beta gem which will evolve over time. Feel free to give us bugs or ideas (or even better, contributions ! )

Thank you !

kud commented 5 years ago

By any chance, if you need it for French, I put it on a gist: https://gist.github.com/kud/9ad523e592a699d3c414e63607fa096e

kud commented 5 years ago

Another solution with i18n-iso-countries package:

import intlTelInput from "intl-tel-input"
import countries from "i18n-iso-countries"
import countriesFr from "i18n-iso-countries/langs/fr.json"
countries.registerLocale(countriesFr)

const sanitiseForIntlTelInput = (obj) => {
  const resultObject = {}

  Object
    .keys(obj)
    .map(key => {
      resultObject[key.toLowerCase()] = obj[key]
    })

  return resultObject
}

const rawCountriesList = countries.getNames("fr")
const countriesList = sanitiseForIntlTelInput(rawCountriesList)

intlTelInput(elementNode, {
  preferredCountries: ["FR", "BE"],
  localizedCountries: countriesList,
})
lmuzlai commented 2 years ago

Hi gents

I am not a programmer, rather a project manager but I have a basic understanding of programming and i18n. Also I am new to GitHub, so bare with me if I am asking questions in the wrong channel.

We running a project where I considered to use "intl-tel-input". So far as I understood, only English is supported in int-tel-input. I was wondering which languages beside French has been made available by others, if at all? Wouldn't it be great if we would have other languages by default also available?

Due to the fact, that I need the country list in roughly 40 different languages, mostly European languages, I was wondering how we could contribute to the project?