3-letter country codes improperly converted to 2-letter country codes
Original Reporter info from Mantis: pgimeno
-
Reporter name: Pedro Gimeno
Original Reporter info from Mantis: pgimeno
- Reporter name: Pedro Gimeno
Description:
I don't use Lazarus on Windows, but when checking the code I noticed this in the Windows version of GetLanguageIDs:
// some 2 letter codes are not the first two letters of the 3 letter code // there are probably more, but first let us see if there are translations if (Buffer='PRT') then Country:='PT';
So I decided to write a proper ISO-3166-1 3-letter country code to 2-letter country code converter, which I hereby donate to the public domain:
{ Transforms an ISO-3166 3-letter country code into an ISO-3166 2-letter country code. If the result is not aligned to a 3 letter boundary, it's not considered to be in the table, and the first 2 letters are returned instead. The table only contains those 3-letter country codes whose first 2 letters don't match their 2-letter country code. It's been verified that none of the 3-letter codes from the first table appear earlier in the string. } function Country3to2(c3: string): string; var posn: Integer; begin posn := Pos(c3, 'ALAANDAGOATAATGARMAUTBHSBGDBRBBLRBLZBENBESBIHBRNBDICPVCYM' + 'CAFTCDCHLCHNCOMCOGCODCOKCUWDNKSLVGNQESTSWZFLKFROGUFPYFATFGRLGRDGLPGIN' + 'GNBGUYIRQIRLISRJAMKAZPRKKORLBRLBYMACMDGMDVMLTMTQMYTMEXFSMMNEMOZNIUMNP' + 'PAKPLWPNGPRYPCNPOLPRTMAFSPMSENSRBSYCSVKSVNSLBSGSSURSWETUNTURTKMTUVUKR' + 'AREURYWLFESHABW'); if posn mod 3 = 1 then begin posn := posn div 3 * 2; Exit(copy('AXADAOAQAGAMATBSBDBBBYBZBJBQBABNBICVKYCFTDCLCNKMCGCDCKCWDKSVGQEE' + 'SZFKFOGFPFTFGLGDGPGNGWGYIQIEILJMKZKPKRLRLYMOMGMVMTMQYTMXFMMEMZNUMPPKPW' + 'PGPYPNPLPTMFPMSNRSSCSKSISBGSSRSETNTRTMTVUAAEUYWFEHAW', posn + 1, 2)); end; Exit(copy(c3, 1, 2)); end;
to hopefully help in solving that issue. The table contains 93 entries, so there's a good number of countries that were being incorrectly determined.
Mantis conversion info:
- Mantis ID: 37938
- OS: Windows
- Build: 47066
- Platform: x86_64, build: trunk r47066