automatische Erkennung der Sprache - wie?

grott

Grünschnabel
Ich will mit C++ ein Linuxtool schreiben und die Ausgabe in Englisch und Deutsch ermöglichen.
Bisher mach ich das, indem ich einfach d oder e als Parameter an das Tool übergebe.
Mir wärs aber lieber, wenn das Tool selber erkennen würde "in welchem Land es gerade ist" ;)

mein erster Denkansatz ist, das Tastaturlayout auszulesen. also wenn qwerty -> dann englisch und bei qwertz -> deutsch.
Allerdings hab ich keine Ahnung wie ich das anstell, kann mir da jemand helfen?

oder gibts noch ne bessere Möglichkeit?

danke schonmal
 
stimmt, klingt ganz gut
nur wie bekomm ich denn den inhalt der $LANG in mein C-tool?

hab noch was andres gefunden, wo ich mich auch mal durchwühlen werd: http://directory.fsf.org/gettext.html


EDIT: $LANG geht leider nicht, weil es nicht standardmäßig gesetzt wird, zumindest nicht bei SuSE - dort muss es erst in der .profile auskommentiert werden
somit kann ich das leider nicht verwenden
 
Zuletzt bearbeitet:
habs selber gefunden:

Item Value
Header file locale.h
Declaration char *setlocale(int type, const char *locale);
Function set local information


type must be one of the following macros (defined in ):

1. LC_ALL: refers to all localization categories.
2. LC_COLLATE: affects the operation of the strcoll() function.
3. LC_CTYPE: alters the way the character functions work.
4. LC_MONETARY: determines the monetary format.
5. LC_NUMERIC: changes the decimal-point character for formatted input/output functions.
6. LC_TIME: determines the behavior of the strftime() function.

The setlocale() function returns a pointer to a string associated with the type parameter.

Display the current locale setting:

#include <locale.h>
#include <stdio.h>

int main(void)
{
printf(setlocale(LC_ALL, ""));

return 0;
}

http://www.java2s.com/Tutorial/C/0460__time.h/setlocale.htm
 
Zurück