Merge pull request #26896 from neovim/backport-25602-to-release-0.9

[Backport release-0.9] refactor(lang): reduce scope of HAVE_WORKING_LIBINTL #ifdefs
This commit is contained in:
bfredl
2024-01-05 09:25:21 +01:00
committed by GitHub
4 changed files with 31 additions and 48 deletions

View File

@@ -2092,10 +2092,9 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, expa
set_context_in_runtime_cmd(xp, arg);
break;
#ifdef HAVE_WORKING_LIBINTL
case CMD_language:
return set_context_in_lang_cmd(xp, arg);
#endif
case CMD_profile:
set_context_in_profile_cmd(xp, arg);
break;
@@ -2606,10 +2605,8 @@ static int ExpandOther(char *pat, expand_T *xp, regmatch_T *rmp, char ***matches
{ EXPAND_AUGROUP, expand_get_augroup_name, true, false },
{ EXPAND_SIGN, get_sign_name, true, true },
{ EXPAND_PROFILE, get_profile_name, true, true },
#ifdef HAVE_WORKING_LIBINTL
{ EXPAND_LANGUAGE, get_lang_arg, true, false },
{ EXPAND_LOCALES, get_locales, true, false },
#endif
{ EXPAND_ENV_VARS, get_env_name, true, true },
{ EXPAND_USER, get_users, true, false },
{ EXPAND_ARGLIST, get_arglist_name, true, false },

View File

@@ -138,10 +138,6 @@ struct dbg_stuff {
# include "ex_docmd.c.generated.h"
#endif
#ifndef HAVE_WORKING_LIBINTL
# define ex_language ex_ni
#endif
// Declare cmdnames[].
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "ex_cmds_defs.generated.h"

View File

@@ -17,7 +17,7 @@
# undef setlocale
# endif
#else
# define _(x) (x)
# define _(x) ((char *)(x))
# define N_(x) x
# define NGETTEXT(x, xs, n) ((n) == 1 ? (x) : (xs))
# define bindtextdomain(x, y) // empty

View File

@@ -70,14 +70,17 @@ char *get_mess_lang(void)
return is_valid_mess_lang(p) ? p : NULL;
}
// Complicated #if; matches with where get_mess_env() is used below.
#ifdef HAVE_WORKING_LIBINTL
/// Get the language used for messages from the environment.
///
/// This uses LC_MESSAGES when available, which it is for most systems we build for
/// except for windows. Then fallback to get the value from the envirionment
/// ourselves, and use LC_CTYPE as a last resort.
static char *get_mess_env(void)
{
char *p;
p = (char *)os_getenv("LC_ALL");
#ifdef LC_MESSAGES
return get_locale_val(LC_MESSAGES);
#else
char *p = (char *)os_getenv("LC_ALL");
if (p == NULL) {
p = (char *)os_getenv("LC_MESSAGES");
if (p == NULL) {
@@ -91,8 +94,8 @@ static char *get_mess_env(void)
}
}
return p;
}
#endif
}
/// Set the "v:lang" variable according to the current locale setting.
/// Also do "v:lc_time"and "v:ctype".
@@ -103,16 +106,7 @@ void set_lang_var(void)
loc = get_locale_val(LC_CTYPE);
set_vim_var_string(VV_CTYPE, loc, -1);
// When LC_MESSAGES isn't defined use the value from $LC_MESSAGES, fall
// back to LC_CTYPE if it's empty.
#ifdef HAVE_WORKING_LIBINTL
loc = get_mess_env();
#elif defined(LC_MESSAGES)
loc = get_locale_val(LC_MESSAGES);
#else
// In Windows LC_MESSAGES is not defined fallback to LC_CTYPE
loc = get_locale_val(LC_CTYPE);
#endif
set_vim_var_string(VV_LANG, loc, -1);
loc = get_locale_val(LC_TIME);
@@ -144,8 +138,6 @@ void init_locale(void)
TIME_MSG("locale set");
}
#ifdef HAVE_WORKING_LIBINTL
/// ":language": Set the language (locale).
///
/// @param eap
@@ -347,8 +339,6 @@ char *get_locales(expand_T *xp, int idx)
return locales[idx];
}
#endif
void lang_init(void)
{
#ifdef __APPLE__