1. Summary
  2. Files
  3. Support
  4. Report Spam
  5. Create account
  6. Log in

Detecting systems default language

Talk about ideas and the code.

Detecting systems default language

Postby pkeus » Sat May 11, 2013 6:15 pm

In revision 324, I added support to detect systems default language. However, since I didn't find a way to do this just with the means of the C++-Standard (getlocale() returns language names in an unusable form), I was only able to implement this for Win32 environments.

Thus, we need a proper implementation for Linux (or a standard-conformant one for all systems, if there is one, which I doubt). The function where to implement is CTranslation::GetSystemDefaultLang() in translations.cpp. It should return something like "en_US", as we use it in our translation file names.
pkeus
 
Posts: 100
Joined: Tue Nov 02, 2010 7:16 pm

Re: Detecting systems default language

Postby cousteau » Mon May 20, 2013 2:31 pm

I tried this C code on Linux and Wine with similar results:
Code: Select all
#include <stdio.h>
#include <locale.h>
int main(void)
{
    printf("Locale = %s\n", setlocale(LC_ALL, NULL));
    setlocale(LC_ALL, "");
    printf("Locale (after setlocale(LC_ALL, \"\")) = %s\n", setlocale(LC_ALL, NULL));
    return 0;
}


Linux:
Code: Select all
Locale = C
Locale (after setlocale(LC_ALL, "")) = es_ES.UTF-8


Windows:
Code: Select all
Locale = C
Locale (after setlocale(LC_ALL, "")) = Spanish_Spain.1252


So the default locale is C, and once set to the system's default, it's of the form <language>_<country>[.<encoding>]. The problem is that the C standard (and probably C++) doesn't specify what exactly it looks like, so Windows and Linux use almost the same format, but one with complete names and the other with ISO 639 and ISO 3166 abbreviated codes. But I guess that a list with both short and long names could do the trick, or else different lists for different OSes.
cousteau
 
Posts: 22
Joined: Sat May 29, 2010 12:18 pm

Re: Detecting systems default language

Postby pkeus » Mon May 20, 2013 2:41 pm

Or just use different functions. es_ES is what we need.
pkeus
 
Posts: 100
Joined: Tue Nov 02, 2010 7:16 pm


Return to Developer Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron