Author: cazfi Date: Mon May 9 15:53:48 2016 New Revision: 32634 URL: http://svn.gna.org/viewcvs/freeciv?rev=32634&view=rev Log: Added low-level switch_lang() function. It has no users in the codebase yet.
See patch #7179 Modified: trunk/utility/fcintl.c trunk/utility/fcintl.h trunk/utility/shared.c trunk/utility/shared.h Modified: trunk/utility/fcintl.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/utility/fcintl.c?rev=32634&r1=32633&r2=32634&view=diff ============================================================================== --- trunk/utility/fcintl.c (original) +++ trunk/utility/fcintl.c Mon May 9 15:53:48 2016 @@ -1,4 +1,4 @@ -/********************************************************************** +/*********************************************************************** Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -24,7 +24,7 @@ static bool autocap = FALSE; -/********************************************************************** +/*********************************************************************** Some strings are ambiguous for translation. For example, "Game" is something you play (like Freeciv!) or animals that can be hunted. To distinguish strings for translation, we qualify them with a prefix @@ -86,9 +86,9 @@ /********************************************************************** Translation opts in to automatic capitalization features. ***********************************************************************/ -void capitalization_opt_in(void) +void capitalization_opt_in(bool opt_in) { - autocap = TRUE; + autocap = opt_in; } /********************************************************************** Modified: trunk/utility/fcintl.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/utility/fcintl.h?rev=32634&r1=32633&r2=32634&view=diff ============================================================================== --- trunk/utility/fcintl.h (original) +++ trunk/utility/fcintl.h Mon May 9 15:53:48 2016 @@ -1,4 +1,4 @@ -/********************************************************************** +/*********************************************************************** Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -75,7 +75,7 @@ const char *skip_intl_qualifier_prefix(const char *str); char *capitalized_string(const char *str); void free_capitalized(char *str); -void capitalization_opt_in(void); +void capitalization_opt_in(bool opt_in); bool is_capitalization_enabled(void); const char *get_locale_dir(void); Modified: trunk/utility/shared.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/utility/shared.c?rev=32634&r1=32633&r2=32634&view=diff ============================================================================== --- trunk/utility/shared.c (original) +++ trunk/utility/shared.c Mon May 9 15:53:48 2016 @@ -1557,6 +1557,51 @@ return langname; } +#ifdef FREECIV_ENABLE_NLS +/*************************************************************************** + Update autocap behavior to match current language. +***************************************************************************/ +static void autocap_update(void) +{ + char *autocap_opt_in[] = { "fi", NULL }; + int i; + bool ac_enabled = FALSE; + + char *lang = getenv("LANG"); + + if (lang != NULL && lang[0] != '\0' && lang[1] != '\0') { + for (i = 0; autocap_opt_in[i] != NULL && !ac_enabled; i++) { + if (lang[0] == autocap_opt_in[i][0] + && lang[1] == autocap_opt_in[i][1]) { + ac_enabled = TRUE; + break; + } + } + } + + capitalization_opt_in(ac_enabled); +} +#endif /* FREECIV_ENABLE_NLS */ + +/*************************************************************************** + Switch to specified LANG +***************************************************************************/ +void switch_lang(const char *lang) +{ +#ifdef FREECIV_ENABLE_NLS + setenv("LANG", lang, TRUE); + + (void) setlocale(LC_ALL, ""); + (void) bindtextdomain("freeciv-core", get_locale_dir()); + + autocap_update(); + + log_normal("LANG set to %s", lang); +#else /* FREECIV_ENABLE_NLS */ + fc_assert(FALSE); +#endif /* FREECIV_ENABLE_NLS */ +} + /*************************************************************************** Setup for Native Language Support, if configured to use it. (Call this only once, or it may leak memory.) @@ -1612,23 +1657,7 @@ grouping_sep = fc_strdup(lc->thousands_sep); } - { - char *autocap_opt_in[] = { "fi", NULL }; - int i; - bool ac_enabled = FALSE; - - char *lang = getenv("LANG"); - - if (lang != NULL && lang[0] != '\0' && lang[1] != '\0') { - for (i = 0; autocap_opt_in[i] != NULL && !ac_enabled; i++) { - if (lang[0] == autocap_opt_in[i][0] - && lang[1] == autocap_opt_in[i][1]) { - ac_enabled = TRUE; - capitalization_opt_in(); - } - } - } - } + autocap_update(); #endif /* ENABLE_NLS */ } Modified: trunk/utility/shared.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/utility/shared.h?rev=32634&r1=32633&r2=32634&view=diff ============================================================================== --- trunk/utility/shared.h (original) +++ trunk/utility/shared.h Mon May 9 15:53:48 2016 @@ -207,6 +207,7 @@ void init_nls(void); void free_nls(void); char *setup_langname(void); +void switch_lang(const char *lang); void dont_run_as_root(const char *argv0, const char *fallback); _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits