0

Today I review some code and saw this! Any thoughts about this way? Maybe you know best way? I think it's veeery slow method :)

string GetLocale(int cp) {
        if (cp == 1078) { return "Afrikaans(af,af)"; }
        if (cp == 1052) { return "Albanian(sq,sq)"; }
        if (cp == 1118) { return "Amharic(am,am)"; }
        if (cp == 5121) { return "Arabic - Algeria(ar,ar-dz)"; }
        if (cp == 15361) { return "Arabic - Bahrain(ar,ar-bh)"; }
        if (cp == 3073) { return "Arabic - Egypt(ar,ar-eg)"; }
        if (cp == 2049) { return "Arabic - Iraq(ar,ar-iq)"; }
        etc...
Dima Vegas
  • 11
  • 1
  • 2
  • Codepages and Locales are two very different things. AFAIK, there is no Win32 API to map one to the other, which is why the code is doing it manually. Though, the numbers shown in this code are not valid codepage identifiers, so what are they supposed to be representing exactly? What input does `GetLocale()` get called with exactly? In any case, a single `switch` statement would be faster than a bunch of `if` statements: `switch (cp) { case 1078: return "Afrikaans(af,af)"; case 1052: return "Albanian(sq,sq)"; case 1118: return "Amharic(am,am)"; ... }` – Remy Lebeau Apr 24 '19 at 23:29
  • Numbers is LCID Decimals and it's valid. – Dima Vegas Apr 25 '19 at 00:20
  • Then the name of the `cp` parameter is misleading since the input is not a codepage identifier. It should be renamed to something more meaningful, such as `localeID`. In any case, now knowing the input is supposed to be locale IDs, have a look at the `GetLocaleInfo()` function, which can return a locale Name given a locale ID. – Remy Lebeau Apr 25 '19 at 00:26

0 Answers0