<URL: http://bugs.freeciv.org/Ticket/Display.html?id=39702 >

> [dmarks - Mo 17. Sep 2007, 23:12:14]:
> 
> On 9/18/07, Christian Prochaska <[EMAIL PROTECTED]>
> wrote:
> >
> > <URL: http://bugs.freeciv.org/Ticket/Display.html?id=39702 >
> >
> > Locale dependent font selection should be possible. Some code for
> locale
> > detection is already present in utility/support.c. Now I only need
> to
> > know which specific additional fonts should be distributed for which
> > locales.
> >
> 
> For zh_CN : fireflysung.ttf -
> http://www.study-area.org/apt/firefly-font/ - Arphic Public License:
> http://unifont.org/fontguide/fontlicenses/apl.txt
> 
> For ja: sazanami-gothic.ttf - http://sourceforge.jp/projects/efont/ -
> Licensing: http://cvs.sourceforge.jp/cgi-
> bin/viewcvs.cgi/efont/sazanami/README?rev=1.5&view=auto
> 
> For ko: UnDotum.ttf - http://kldp.net/projects/unfonts/ - GPL
> 
>  ~Daniel
> 

Patch attached. It adds a common function get_langname() in
utility/shared.c that returns the name of the locale (from LANG or by
Windows-specific mapping).

Index: client/gui-sdl/themespec.c
===================================================================
--- client/gui-sdl/themespec.c	(revision 13619)
+++ client/gui-sdl/themespec.c	(working copy)
@@ -721,7 +721,16 @@
   sz_strlcpy(t->name, theme_name);
   t->priority = secfile_lookup_int(file, "themespec.priority");
   
-  c = secfile_lookup_str(file, "themespec.font_file");
+  char *langname = get_langname();
+  if (strstr(langname, "zh_CN") != NULL) {
+    c = secfile_lookup_str(file, "themespec.font_file_zh_CN");
+  } else if (strstr(langname, "ja") != NULL) {
+    c = secfile_lookup_str(file, "themespec.font_file_ja");
+  } else if (strstr(langname, "ko") != NULL) {
+    c = secfile_lookup_str(file, "themespec.font_file_ko");
+  } else {
+    c = secfile_lookup_str(file, "themespec.font_file");
+  }
   t->font_filename = datafilename(c);
   if (t->font_filename) {
     t->font_filename = mystrdup(t->font_filename);
Index: data/themes/gui-sdl/human/theme.themespec
===================================================================
--- data/themes/gui-sdl/human/theme.themespec	(revision 13619)
+++ data/themes/gui-sdl/human/theme.themespec	(working copy)
@@ -9,6 +9,9 @@
 
 ; The font to be used:
 font_file         = "themes/gui-sdl/human/DejaVuSans.ttf"
+font_file_zh_CN   = "themes/gui-sdl/human/fireflysung.ttf"
+font_file_ja      = "themes/gui-sdl/human/sazanami-gothic.ttf"
+font_file_ko      = "themes/gui-sdl/human/UnDotum.ttf"
 default_font_size = 18
 
 ; Below, the graphics spec files; must be somewhere (anywhere) in 
Index: utility/shared.c
===================================================================
--- utility/shared.c	(revision 13619)
+++ utility/shared.c	(working copy)
@@ -1223,6 +1223,97 @@
   }
 }
 
+char *get_langname(void)
+{
+  char *langname = NULL;      
+        
+#ifdef ENABLE_NLS
+
+  langname = getenv("LANG");
+  
+#ifdef WIN32_NATIVE
+  /* set LANG by hand if it is not set */
+  if (!langname) {
+    switch (PRIMARYLANGID(GetUserDefaultLangID())) {
+      case LANG_ARABIC:
+        return "ar";
+      case LANG_CATALAN:
+        return "ca";
+      case LANG_CZECH:
+        return "cs";
+      case LANG_DANISH:
+        return "da"; 
+      case LANG_GERMAN:
+        return "de";
+      case LANG_GREEK:
+        return "el";
+      case LANG_ENGLISH:
+        switch (SUBLANGID(GetUserDefaultLangID())) {
+          case SUBLANG_ENGLISH_UK:
+            return "en_GB";
+          default:
+            return "en"; 
+        }
+      case LANG_SPANISH:
+        return "es";
+      case LANG_ESTONIAN:
+        return "et";
+      case LANG_FARSI:
+        return "fa";
+      case LANG_FINNISH:
+        return "fi";
+      case LANG_FRENCH:
+        return "fr";
+      case LANG_HEBREW:
+        return "he";
+      case LANG_HUNGARIAN:
+        return "hu";
+      case LANG_ITALIAN:
+        return "it";
+      case LANG_JAPANESE:
+        return "ja";
+      case LANG_KOREAN:
+        return "ko";
+      case LANG_LITHUANIAN:
+        return "lt";
+      case LANG_DUTCH:
+        return "nl";
+      case LANG_NORWEGIAN:
+        switch (SUBLANGID(GetUserDefaultLangID())) {
+          case SUBLANG_NORWEGIAN_BOKMAL:
+            return "nb";
+          default:
+            return "no";
+        }
+      case LANG_POLISH:
+        return "pl";
+      case LANG_PORTUGUESE:
+        switch (SUBLANGID(GetUserDefaultLangID())) {
+          case SUBLANG_PORTUGUESE_BRAZILIAN:
+            return "pt_BR";
+          default:
+            return "pt";
+        }
+      case LANG_ROMANIAN:
+        return "ro";
+      case LANG_RUSSIAN:
+        return "ru";
+      case LANG_SWEDISH:
+        return "sv";
+      case LANG_TURKISH:
+        return "tr";
+      case LANG_UKRAINIAN:
+        return "uk";
+      case LANG_CHINESE:
+        return "zh_CN";
+    }
+  }
+#endif /* WIN32_NATIVE */
+#endif /* ENABLE_NLS */
+
+  return langname;
+}
+        
 /***************************************************************************
   Setup for Native Language Support, if configured to use it.
   (Call this only once, or it may leak memory.)
@@ -1237,55 +1328,14 @@
   grouping_sep = mystrdup(",");
 
 #ifdef ENABLE_NLS
+
 #ifdef WIN32_NATIVE
-  /* set LANG by hand if it is not set */
-  if (!getenv("LANG")) {
-    char *langname = NULL;
+  char *langname = get_langname();  
+  if (langname) {
+    static char envstr[40];
 
-    switch (PRIMARYLANGID(LANGIDFROMLCID(GetUserDefaultLCID()))) {
-    case LANG_SPANISH:
-      langname = "es";
-      break;
-    case LANG_GERMAN:
-      langname = "de";
-      break;
-    case LANG_ENGLISH:
-      langname = "en";
-      break;
-    case LANG_FRENCH:
-      langname = "fr";
-      break;
-    case LANG_DUTCH:
-      langname = "nl";
-      break;
-    case LANG_POLISH:
-      langname = "pl";
-      break;
-    case LANG_HUNGARIAN:
-      langname = "hu";
-      break;
-    case LANG_NORWEGIAN:
-      langname = "no";
-      break;
-    case LANG_JAPANESE:
-      langname = "ja";
-      break;
-    case LANG_PORTUGUESE:
-      langname = "pt";
-      break;
-    case LANG_ROMANIAN:
-      langname = "ro";
-      break;
-    case LANG_RUSSIAN:
-      langname = "ru";
-      break;
-    }
-    if (langname) {
-      static char envstr[40];
-
-      my_snprintf(envstr, sizeof(envstr), "LANG=%s", langname);
-      putenv(envstr);
-    }
+    my_snprintf(envstr, sizeof(envstr), "LANG=%s", langname);
+    putenv(envstr);
   }
 #endif
 
Index: utility/shared.h
===================================================================
--- utility/shared.h	(revision 13619)
+++ utility/shared.h	(working copy)
@@ -196,6 +196,7 @@
 char **datafilenames(const char *filename);
 char *datafilename_required(const char *filename);
 
+char *get_langname(void);
 void init_nls(void);
 void dont_run_as_root(const char *argv0, const char *fallback);
 
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to