* * *

Author Topic: Convert iso 639 code to Language name :)  (Read 4732 times)

ojZim

  • New member
  • *
  • Posts: 14
Convert iso 639 code to Language name :)
« on: July 27, 2013, 02:41:16 pm »
Hello to all  ;D
How can I convert iso-639 code to name of language in lazarus?

for example:
en > English
fa > Persian
fr > French
de > Deutsch

for this work, is it good idea to create two TStringList and get language name from them? or exists a better and easier way?

Thank you.

taazz

  • Hero Member
  • *****
  • Posts: 3693
Re: Convert iso 639 code to Language name :)
« Reply #1 on: July 27, 2013, 02:50:02 pm »
a single string list might be easier the strings will have the form of
en=English
fa=Persian
fr=French
de=Deutsch
and you access them using the values property eg.
showmessage('fa is '+MyStringList.Values['fa']);
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

ojZim

  • New member
  • *
  • Posts: 14
Re: Convert iso 639 code to Language name :)
« Reply #2 on: July 27, 2013, 02:52:49 pm »
a single string list might be easier the strings will have the form of
en=English
fa=Persian
fr=French
de=Deutsch
and you access them using the values property eg.
showmessage('fa is '+MyStringList.Values['fa']);

Yes, I know this way. But I'm looking for a better way to do that... I don't like to add language names into a TStringList  :'(

typo

  • Hero Member
  • *****
  • Posts: 3051
« Last Edit: July 27, 2013, 03:51:46 pm by typo »

howardpc

  • Hero Member
  • *****
  • Posts: 2052
Re: Convert iso 639 code to Language name :)
« Reply #4 on: July 27, 2013, 03:52:35 pm »
I don't like to add language names into a TStringList
Why ever not?
Anyway, Pascal offers many ways to achieve the same end. You could use a routine something like this (if you don't mind hard-coding data in a case construct):
Code: [Select]
function IsoToLang(const iso: string): string;
begin
  case lowerCase(iso) of
   'de': Result:= 'Deutsch';
   'en': Result:= 'English';
   'fa': Result:= 'Persian';
   'fr': Result:= 'French';
   else Result:= 'unknown';
  end;
end;   

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Convert iso 639 code to Language name :)
« Reply #5 on: July 27, 2013, 04:02:38 pm »
@ojZim

Use your imagination. Write a program to edit the list for you and generate the code you will need for the case statement.

taazz

  • Hero Member
  • *****
  • Posts: 3693
Re: Convert iso 639 code to Language name :)
« Reply #6 on: July 27, 2013, 04:06:30 pm »
The best solution is to use the OS functions to do that if the OS defines them, after that I would use a lazy technique like the one howardpc described it is the only one that uses no memory outside the procedure and doesn't place any burden to your application memory usage. I might change it a bit to use resource strings for the language names so it can be translated if needed be but that's the max  I'll go.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Convert iso 639 code to Language name :)
« Reply #7 on: July 27, 2013, 05:10:44 pm »
Why ISO 639?

Quote
I don't like to add language names into a TStringList  :'(

Dear ojZim, if you don't like to write code you should not be a programmer.

ISO 639 list has languages wich Windows list has not and vice-versa. ISO 639 list has no sublanguages, for example.
« Last Edit: July 27, 2013, 05:48:45 pm by typo »

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Convert iso 639 code to Language name :)
« Reply #8 on: July 27, 2013, 06:23:29 pm »

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Convert iso 639 code to Language name :)
« Reply #9 on: July 27, 2013, 07:20:18 pm »
In consideration of the other forum members who may read this I will post an almost complete code made by fusioning the two lists:

Code: [Select]
'aa': Result := 'Afar';
'ab': Result := 'Abkhaz';
'ae': Result := 'Avestan';
'af': Result := 'Afrikaans ';
'af': Result := 'Afrikaans';
'ak': Result := 'Akan';
'am': Result := 'Amharic';
'an': Result := 'Aragonese';
'ar': Result := 'Arabic';
'ar-ae': Result := 'Arabic (U.A.E.)';
'ar-bh': Result := 'Arabic (Bahrain) ';
'ar-dz': Result := 'Arabic (Algeria) ';
'ar-eg': Result := 'Arabic (Egypt) ';
'ar-iq': Result := 'Arabic (Iraq)';
'ar-jo': Result := 'Arabic (Jordan) ';
'ar-kw': Result := 'Arabic (Kuwait) ';
'ar-lb': Result := 'Arabic (Lebanon)';
'ar-ly': Result := 'Arabic (Libya)';
'ar-ma': Result := 'Arabic (Morocco)';
'ar-om': Result := 'Arabic (Oman)';
'ar-qa': Result := 'Arabic (Qatar)';
'ar-sa': Result := 'Arabic (Saudi Arabia) ';
'ar-sy': Result := 'Arabic (Syria)';
'ar-tn': Result := 'Arabic (Tunisia) ';
'ar-ye': Result := 'Arabic (Yemen) ';
'as': Result := 'Assamese';
'av': Result := 'Avaric';
'ay': Result := 'Aymara';
'az': Result := 'Azerbaijani';
'ba': Result := 'Bashkir';
'be': Result := 'Belarusian ';
'bg': Result := 'Bulgarian';
'bh': Result := 'Bihari';
'bi': Result := 'Bislama';
'bm': Result := 'Bambara';
'bn': Result := 'Bengali; Bangla';
'bo': Result := 'Tibetan Standard, Tibetan, Central';
'br': Result := 'Breton';
'bs': Result := 'Bosnian';
'ca': Result := 'Catalan; Valencian';
'ce': Result := 'Chechen';
'ch': Result := 'Chamorro';
'co': Result := 'Corsican';
'cr': Result := 'Cree';
'cs': Result := 'Czech';
'cu': Result := 'Old Church Slavonic, Church Slavic, Church Slavonic, Old Bulgarian, Old Slavonic';
'cv': Result := 'Chuvash';
'cy': Result := 'Welsh';
'da': Result := 'Danish ';
'de': Result := 'German (Standard) ';
'de-at': Result := 'German (Austria) ';
'de-ch': Result := 'German (Switzerland)';
'de-li': Result := 'German (Liechtenstein) ';
'de-lu': Result := 'German (Luxembourg)';
'dv': Result := 'Divehi; Dhivehi; Maldivian;';
'dz': Result := 'Dzongkha';
'ee': Result := 'Ewe';
'el': Result := 'Greek, Modern';
'en': Result := 'English';
'en-au': Result := 'English (Australia) ';
'en-bz': Result := 'English (Belize)';
'en-ca': Result := 'English (Canada)';
'en-gb': Result := 'English (United Kingdom)';
'en-ie': Result := 'English (Ireland)';
'en-jm': Result := 'English (Jamaica)';
'en-nz': Result := 'English (New Zealand) ';
'en-tt': Result := 'English (Trinidad) ';
'en-us': Result := 'English (United States) ';
'en-za': Result := 'English (South Africa) ';
'eo': Result := 'Esperanto';
'es': Result := 'Spanish (Spain)';
'es-ar': Result := 'Spanish (Argentina) ';
'es-bo': Result := 'Spanish (Bolivia)';
'es-cl': Result := 'Spanish (Chile) ';
'es-co': Result := 'Spanish (Colombia) ';
'es-cr': Result := 'Spanish (Costa Rica) ';
'es-do': Result := 'Spanish (Dominican Republic) ';
'es-ec': Result := 'Spanish (Ecuador)';
'es-gt': Result := 'Spanish (Guatemala)';
'es-hn': Result := 'Spanish (Honduras)';
'es-mx': Result := 'Spanish (Mexico) ';
'es-ni': Result := 'Spanish (Nicaragua) ';
'es-pa': Result := 'Spanish (Panama)';
'es-pe': Result := 'Spanish (Peru)';
'es-pr': Result := 'Spanish (Puerto Rico)';
'es-py': Result := 'Spanish (Paraguay) ';
'es-sv': Result := 'Spanish (El Salvador) ';
'es-uy': Result := 'Spanish (Uruguay)';
'es-ve': Result := 'Spanish (Venezuela)';
'et': Result := 'Estonian';
'eu': Result := 'Basque';
'fa': Result := 'Persian';
'ff': Result := 'Fula; Fulah; Pulaar; Pular';
'fi': Result := 'Finnish';
'fj': Result := 'Fijian';
'fo': Result := 'Faeroese ';
'fr': Result := 'French';
'fr-be': Result := 'French (Belgium) ';
'fr-ca': Result := 'French (Canada)';
'fr-ch': Result := 'French (Switzerland) ';
'fr-lu': Result := 'French (Luxembourg)';
'fy': Result := 'Western Frisian';
'ga': Result := 'Irish';
'gd': Result := 'Scottish Gaelic; Gaelic';
'gl': Result := 'Galician';
'gn': Result := 'Guaraní';
'gu': Result := 'Gujarati';
'gv': Result := 'Manx';
'ha': Result := 'Hausa';
'he': Result := 'Hebrew (modern)';
'hi': Result := 'Hindi';
'ho': Result := 'Hiri Motu';
'hr': Result := 'Croatian';
'ht': Result := 'Haitian; Haitian Creole';
'hu': Result := 'Hungarian';
'hy': Result := 'Armenian';
'hz': Result := 'Herero';
'ia': Result := 'Interlingua';
'id': Result := 'Indonesian';
'ie': Result := 'Interlingue';
'ig': Result := 'Igbo';
'ii': Result := 'Nuosu';
'ik': Result := 'Inupiaq';
'io': Result := 'Ido';
'is': Result := 'Icelandic';
'it': Result := 'Italian';
'it-ch': Result := 'Italian (Switzerland) ';
'iu': Result := 'Inuktitut';
'ja': Result := 'Japanese';
'ji': Result := 'Yiddish ';
'jv': Result := 'Javanese';
'ka': Result := 'Georgian';
'kg': Result := 'Kongo';
'ki': Result := 'Kikuyu, Gikuyu';
'kj': Result := 'Kwanyama, Kuanyama';
'kk': Result := 'Kazakh';
'kl': Result := 'Kalaallisut, Greenlandic';
'km': Result := 'Khmer';
'kn': Result := 'Kannada';
'ko': Result := 'Korean';
'kr': Result := 'Kanuri';
'ks': Result := 'Kashmiri';
'ku': Result := 'Kurdish';
'kv': Result := 'Komi';
'kw': Result := 'Cornish';
'ky': Result := 'Kyrgyz';
'la': Result := 'Latin';
'lb': Result := 'Luxembourgish, Letzeburgesch';
'lg': Result := 'Ganda';
'li': Result := 'Limburgish, Limburgan, Limburger';
'ln': Result := 'Lingala';
'lo': Result := 'Lao';
'lt': Result := 'Lithuanian';
'lu': Result := 'Luba-Katanga';
'lv': Result := 'Latvian';
'mg': Result := 'Malagasy';
'mh': Result := 'Marshallese';
'mi': Result := 'Māori';
'mk': Result := 'Macedonian';
'ml': Result := 'Malayalam';
'mn': Result := 'Mongolian';
'mr': Result := 'Marathi (Marāṭhī)';
'ms': Result := 'Malay';
'ms': Result := 'Malaysian';
'mt': Result := 'Maltese';
'my': Result := 'Burmese';
'na': Result := 'Nauru';
'nb': Result := 'Norwegian Bokmål';
'nd': Result := 'North Ndebele';
'ne': Result := 'Nepali';
'ng': Result := 'Ndonga';
'nl': Result := 'Dutch';
'nl-be': Result := 'Dutch (Belgium) ';
'nn': Result := 'Norwegian Nynorsk';
'no': Result := 'Norwegian';
'nr': Result := 'South Ndebele';
'nv': Result := 'Navajo, Navaho';
'ny': Result := 'Chichewa; Chewa; Nyanja';
'oc': Result := 'Occitan';
'oj': Result := 'Ojibwe, Ojibwa';
'om': Result := 'Oromo';
'or': Result := 'Oriya';
'os': Result := 'Ossetian, Ossetic';
'pa': Result := 'Panjabi, Punjabi';
'pi': Result := 'Pāli';
'pl': Result := 'Polish';
'ps': Result := 'Pashto, Pushto';
'pt': Result := 'Portuguese (Portugal)';
'pt-br': Result := 'Portuguese (Brazil) ';
'qu': Result := 'Quechua';
'rm': Result := 'Rhaeto-Romanic ';
'rn': Result := 'Kirundi';
'ro': Result := 'Romanian';
'ro-mo': Result := 'Romanian (Republic of Moldova) ';
'ru': Result := 'Russian';
'ru-mo': Result := 'Russian (Republic of Moldova) ';
'rw': Result := 'Kinyarwanda';
'sa': Result := 'Sanskrit (Saṁskṛta)';
'sb': Result := 'Sorbian ';
'sc': Result := 'Sardinian';
'sd': Result := 'Sindhi';
'se': Result := 'Northern Sami';
'sg': Result := 'Sango';
'si': Result := 'Sinhala, Sinhalese';
'sk': Result := 'Slovak';
'sl': Result := 'Slovenian';
'sm': Result := 'Samoan';
'sn': Result := 'Shona';
'so': Result := 'Somali';
'sq': Result := 'Albanian';
'sr': Result := 'Serbian';
'ss': Result := 'Swati';
'st': Result := 'Southern Sotho';
'su': Result := 'Sundanese';
'sv': Result := 'Swedish';
'sv-fi': Result := 'Swedish (Finland) ';
'sw': Result := 'Swahili';
'sx': Result := 'Sutu ';
'sz': Result := 'Sami (Lappish)';
'ta': Result := 'Tamil';
'te': Result := 'Telugu';
'tg': Result := 'Tajik';
'th': Result := 'Thai';
'ti': Result := 'Tigrinya';
'tk': Result := 'Turkmen';
'tl': Result := 'Tagalog';
'tn': Result := 'Tswana';
'to': Result := 'Tonga (Tonga Islands)';
'tr': Result := 'Turkish';
'ts': Result := 'Tsonga';
'tt': Result := 'Tatar';
'tw': Result := 'Twi';
'ty': Result := 'Tahitian';
'ug': Result := 'Uighur, Uyghur';
'uk': Result := 'Ukrainian';
'ur': Result := 'Urdu';
'uz': Result := 'Uzbek';
've': Result := 'Venda';
'vi': Result := 'Vietnamese';
'vo': Result := 'Volapük';
'wa': Result := 'Walloon';
'wo': Result := 'Wolof';
'xh': Result := 'Xhosa';
'yi': Result := 'Yiddish';
'yo': Result := 'Yoruba';
'za': Result := 'Zhuang, Chuang';
'zh': Result := 'Chinese';
'zh-cn': Result := 'Chinese (PRC)';
'zh-hk': Result := 'Chinese (Hong Kong SAR) ';
'zh-sg': Result := 'Chinese (Singapore)';
'zh-tw': Result := 'Chinese (Taiwan) ';
'zu': Result := 'Zulu';


 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus