mirror of
https://github.com/moparisthebest/hexchat
synced 2024-11-22 09:12:22 -05:00
Now the default configuration tries to set the language from the system
locale, and defaults to english if no language match. This closes #473.
This commit is contained in:
parent
951292abe1
commit
473ab16739
@ -41,6 +41,15 @@
|
||||
#define DEF_FONT "Monospace 9"
|
||||
#define DEF_FONT_ALTER "Arial Unicode MS,Lucida Sans Unicode,MS Gothic,Unifont"
|
||||
|
||||
const char const *languages[LANGUAGES_LENGTH] = {
|
||||
"af", "sq", "am", "ast", "az", "eu", "be", "bg", "ca", "zh_CN", /* 0 .. 9 */
|
||||
"zh_TW", "cs", "da", "nl", "en_GB", "en", "et", "fi", "fr", "gl", /* 10 .. 19 */
|
||||
"de", "el", "gu", "hi", "hu", "id", "it", "ja", "kn", "rw", /* 20 .. 29 */
|
||||
"ko", "lv", "lt", "mk", "ml", "ms", "nb", "no", "pl", "pt", /* 30 .. 39 */
|
||||
"pt_BR", "pa", "ru", "sr", "sk", "sl", "es", "sv", "th", "uk", /* 40 .. 49 */
|
||||
"vi", "wa" /* 50 .. */
|
||||
};
|
||||
|
||||
void
|
||||
list_addentry (GSList ** list, char *cmd, char *name)
|
||||
{
|
||||
@ -605,6 +614,60 @@ convert_with_fallback (const char *str, const char *fallback)
|
||||
return utf;
|
||||
}
|
||||
|
||||
static int
|
||||
find_language_number (const char const *lang)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < LANGUAGES_LENGTH; i++)
|
||||
if (!strcmp (lang, languages[i]))
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Return the number of the system language if found, or english otherwise.
|
||||
*/
|
||||
static int
|
||||
get_default_language (void)
|
||||
{
|
||||
const char *locale;
|
||||
char *lang;
|
||||
char *p;
|
||||
int lang_no;
|
||||
|
||||
/* LC_ALL overrides LANG, so we must check it first */
|
||||
locale = g_getenv ("LC_ALL");
|
||||
|
||||
if (!locale)
|
||||
locale = g_getenv ("LANG") ? g_getenv ("LANG") : "en";
|
||||
|
||||
/* we might end up with something like "en_US.UTF-8". We will try to
|
||||
* search for "en_US"; if it fails we search for "en".
|
||||
*/
|
||||
lang = g_strdup (locale);
|
||||
|
||||
if ((p = strchr (lang, '.')))
|
||||
*p='\0';
|
||||
|
||||
lang_no = find_language_number (lang);
|
||||
|
||||
if (lang_no >= 0)
|
||||
{
|
||||
free(lang);
|
||||
return lang_no;
|
||||
}
|
||||
|
||||
if ((p = strchr (lang, '_')))
|
||||
*p='\0';
|
||||
|
||||
lang_no = find_language_number (lang);
|
||||
|
||||
free(lang);
|
||||
|
||||
return lang_no >= 0 ? lang_no : find_language_number ("en");
|
||||
}
|
||||
|
||||
void
|
||||
load_default_config(void)
|
||||
{
|
||||
@ -704,7 +767,7 @@ load_default_config(void)
|
||||
prefs.hex_gui_dialog_height = 256;
|
||||
prefs.hex_gui_dialog_width = 500;
|
||||
prefs.hex_gui_lagometer = 1;
|
||||
prefs.hex_gui_lang = 15;
|
||||
prefs.hex_gui_lang = get_default_language();
|
||||
prefs.hex_gui_pane_left_size = 128; /* with treeview icons we need a bit bigger space */
|
||||
prefs.hex_gui_pane_right_size = 100;
|
||||
prefs.hex_gui_pane_right_size_min = 80;
|
||||
|
@ -24,7 +24,10 @@
|
||||
|
||||
#include "hexchat.h"
|
||||
|
||||
#define LANGUAGES_LENGTH 52
|
||||
|
||||
extern char *xdir;
|
||||
extern const char const *languages[LANGUAGES_LENGTH];
|
||||
|
||||
char *cfg_get_str (char *cfg, const char *var, char *dest, int dest_len);
|
||||
int cfg_get_bool (char *var);
|
||||
@ -47,6 +50,7 @@ void list_addentry (GSList ** list, char *cmd, char *name);
|
||||
int cmd_set (session *sess, char *tbuf, char *word[], char *word_eol[]);
|
||||
int hexchat_open_file (char *file, int flags, int mode, int xof_flags);
|
||||
FILE *hexchat_fopen_file (const char *file, const char *mode, int xof_flags);
|
||||
|
||||
#define XOF_DOMODE 1
|
||||
#define XOF_FULLPATH 2
|
||||
|
||||
|
@ -1017,20 +1017,12 @@ static void
|
||||
set_locale (void)
|
||||
{
|
||||
#ifdef WIN32
|
||||
const char const *langs[]={
|
||||
"af", "sq", "am", "ast", "az", "eu", "be", "bg", "ca", "zh_CN", /* 0 .. 9 */
|
||||
"zh_TW", "cs", "da", "nl", "en_GB", "en", "et", "fi", "fr", "gl", /* 10 .. 19 */
|
||||
"de", "el", "gu", "hi", "hu", "id", "it", "ja", "kn", "rw", /* 20 .. 29 */
|
||||
"ko", "lv", "lt", "mk", "ml", "ms", "nb", "no", "pl", "pt", /* 30 .. 39 */
|
||||
"pt_BR", "pa", "ru", "sr", "sk", "sl", "es", "sv", "th", "uk", /* 40 .. 49 */
|
||||
"vi", "wa" /* 50 .. */
|
||||
};
|
||||
char hexchat_lang[13]; /* LC_ALL= plus 5 chars of hex_gui_lang and trailing \0 */
|
||||
|
||||
strcpy (hexchat_lang, "LC_ALL=");
|
||||
|
||||
if (0 <= prefs.hex_gui_lang && prefs.hex_gui_lang < sizeof(langs)/sizeof(*langs))
|
||||
strcat (hexchat_lang, langs[prefs.hex_gui_lang]);
|
||||
if (0 <= prefs.hex_gui_lang && prefs.hex_gui_lang < LANGUAGES_LENGTH)
|
||||
strcat (hexchat_lang, languages[prefs.hex_gui_lang]);
|
||||
else
|
||||
strcat (hexchat_lang, "en");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user