-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to change language without a restart #14379
Add ability to change language without a restart #14379
Conversation
Two minor issues I found:
|
// Source: https://www.gnu.org/software/gettext/manual/html_node/gettext-grok.html | ||
{ | ||
extern int _nl_msg_cat_cntr; | ||
++_nl_msg_cat_cntr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this won't mess up on systems where they are using some sort of alternative gettext implementation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whilst the documentation says to do this, I found that it wasn't actually needed. So if it's likely to cause issues, could maybe be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related: https://bugs.kde.org/show_bug.cgi?id=365917 (fixed by https://invent.kde.org/frameworks/ki18n/-/commit/543b8ae67c57500bf3cabde75bf1599904d6e482) and also the #14379 (comment) comment below.
Maybe only enable language switching when it can be determined that it works? (e.g. by checking whether translating LANG_CODE works after switching languages)
What do you think about using a |
Yeah I was thinking about this but went with the simpler option to begin with One thing to point out is that |
Updated, please may you retest @y5nw |
Ok, updated. It works as expected for me with This will need to be tested on MSVC stuff, as I've changed code gated by _MSC_VER |
Using |
3cc5132
to
ab5202c
Compare
Rebased. As the ContentDB dialog now requests localised meta, I've added a |
@wsor4035 tested on Windows using the mingw and MSVC builds from GitHub actions. The Mingw build passes the test plan in the opening post, including detecting system language. The MSVC build is not compiled with gettext so does not support translation MSVC left, mingw right |
MSVC appears to be particularly hard to work with (at least from what I tried in a VM). It seems like diff --git a/src/gettext.cpp b/src/gettext.cpp
index 972519116..8825d518d 100644
--- a/src/gettext.cpp
+++ b/src/gettext.cpp
@@ -34,6 +34,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define setlocale(category, localename) \
setlocale(category, MSVC_LocaleLookup(localename))
+static int argc;
+static char** argv;
+
static std::map<std::wstring, std::wstring> glb_supported_locales;
/******************************************************************************/
@@ -115,7 +118,7 @@ static const char* MSVC_LocaleLookup(const char* raw_shortname)
return "";
}
-static void MSVC_LocaleWorkaround(int argc, char* argv[])
+static void MSVC_LocaleWorkaround()
{
errorstream << "MSVC localization workaround active. "
"Restarting " PROJECT_NAME_C " in a new environment!" << std::endl;
@@ -183,7 +186,7 @@ namespace {
/******************************************************************************/
void init_gettext(const char *path, const std::string &configured_language,
- int argc, char *argv[])
+ int _argc, char *_argv[])
{
#if USE_GETTEXT
char *system_language_c = getenv("LANGUAGE");
@@ -205,6 +208,10 @@ void init_gettext(const char *path, const std::string &configured_language,
assert(tdomain);
if (tdomain)
bind_textdomain_codeset(tdomain, "UTF-8");
+#ifdef _MSC_VER
+ argc = _argc;
+ argv = _argv;
+#endif
#endif
#else
@@ -254,21 +261,23 @@ void set_gettext_language(std::string configured_language)
#ifndef SERVER
// Hack to force gettext to see the right environment
if (current_language != configured_language)
- MSVC_LocaleWorkaround(argc, argv);
+ MSVC_LocaleWorkaround();
#else
errorstream << "*******************************************************" << std::endl;
errorstream << "Can't apply locale workaround for server!" << std::endl;
errorstream << "Expect language to be broken!" << std::endl;
errorstream << "*******************************************************" << std::endl;
#endif
-#endif
+#else
// Notify gettext that the language has changed
// Source: https://www.gnu.org/software/gettext/manual/html_node/gettext-grok.html
+ // This does not seem to work when building with MSVC
{
extern int _nl_msg_cat_cntr;
++_nl_msg_cat_cntr;
}
+#endif
#endif
/* no matter what locale is used we need number format to be "C" */ However, switching the language causes MT to crash. Edit: it does also spawn a new instance of MT with the selected language. However, the language setting is not changed. Stack trace reported by Visual Studio 2022
|
Yeah, I didn't read We should probably see if it's still needed - this workaround was added 11 years ago ( 22a59b3 ) and so might not be needed any more. I suggest commenting out MSVC_LocaleWorkaround and seeing if it works |
MSVC+Gettext seems to work on the master branch, but without language switching (obviously).
I tried removing the workaround. The result is that changing the language only updates the translations for strings where a translation is previously not available: That said, I removed the IMO it would be best here to change |
@@ -232,14 +208,73 @@ void init_gettext(const char *path, const std::string &configured_language, | |||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO the _WIN32
check here should be removed since some locales on Linux also do not use a UTF-8 locale by default.
This allows changing the current language without restarting Minetest. Gettext reads the
language
env var for every call, so we just need to change this and notify gettext about the changeTo do
This PR is Ready for Review.
How to test