Skip to content
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

Fix: Workaround for localized texts in DarkRP not loading correctly #3262

Merged
merged 5 commits into from
Jul 25, 2024

Conversation

jjyao88
Copy link
Contributor

@jjyao88 jjyao88 commented Jul 14, 2024

In DarkRP, some in-game notifications are localized and sent from the server.

However, during server initialization, the convar gmod_language doesn't get read correctly. Even if we set gmod_language [geo code] in server.cfg, it returns an empty string at that time, causing all server-side localized texts to be in English instead of the desired language.

To fix this, I've proposed a workaround that delays reading the convar until the server is fully loaded.

And there's a minor concern that the client's language might still be different from the server, leading to incorrect localized texts. I think all localized texts should be handled on the client-side, not the server.

@jjyao88
Copy link
Contributor Author

jjyao88 commented Jul 14, 2024

I just noticed that all pose names in animation menu are not translated as well.

hook.Add("loadCustomDarkRPItems", "loadAnimations", function()
Anims[ACT_GMOD_GESTURE_BOW] = DarkRP.getPhrase("bow")
Anims[ACT_GMOD_TAUNT_MUSCLE] = DarkRP.getPhrase("sexy_dance")
Anims[ACT_GMOD_GESTURE_BECON] = DarkRP.getPhrase("follow_me")
Anims[ACT_GMOD_TAUNT_LAUGH] = DarkRP.getPhrase("laugh")
Anims[ACT_GMOD_TAUNT_PERSISTENCE] = DarkRP.getPhrase("lion_pose")
Anims[ACT_GMOD_GESTURE_DISAGREE] = DarkRP.getPhrase("nonverbal_no")
Anims[ACT_GMOD_GESTURE_AGREE] = DarkRP.getPhrase("thumbs_up")
Anims[ACT_GMOD_GESTURE_WAVE] = DarkRP.getPhrase("wave")
Anims[ACT_GMOD_TAUNT_DANCE] = DarkRP.getPhrase("dance")
end)

I modified the event name to Think by myself in the above code and it seems to work now.

Copy link
Owner

@FPtje FPtje left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I have to be honest, this is the first time I hear of this bug, and the language system has not changed in a long time. I think perhaps there may be something off in your setup. Maybe your server.cfg sets it, but some other config or script unsets it.

@@ -1,7 +1,7 @@
local Anims = {}

-- Load animations after the languages for translation purposes
hook.Add("loadCustomDarkRPItems", "loadAnimations", function()
hook.Add("Think", "loadAnimations", function()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand the problem. Looking quickly at the rest of the file, it seems that the server only uses Anims to see whether an animation is registered. It ignores the actual translation. The client does show the animation in the menu.

Other than that, instead of creating and removing a think hook, on can run a timer.Simple(0,...). Note that either option will run the code quite a bit later than now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, I'm not able to reproduce this issue. This may be due to my misconfiguration on my part. I'll revert this change.


cvars.AddChangeCallback("gmod_language", function(cv, old, new)
selectedLanguage = new
end)

hook.Add("Think", "DarkRPSetLanguage", function()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be covered by the cvars.AddChangeCallback call above? After all, the moment the car goes from empty to set, that function should trigger.

Maybe the empty string check can be moved there instead. That would remove the need of the separate hook.

Copy link
Contributor Author

@jjyao88 jjyao88 Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the cvars.AddChangeCallback above doesn't work at all no matter what language codes I changed from dedicated server-side. This could be the bug directly from Facepunch...
However, I could make it work by starting the server from the main game.

Copy link
Contributor Author

@jjyao88 jjyao88 Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems gmod_language only works for client side by design.

I haven't managed to make cvars.AddChangeCallback("gmod_language", ...) work on server side.

@@ -1,10 +1,18 @@
local rp_languages = {}
local selectedLanguage = GetConVar("gmod_language"):GetString() -- Switch language by setting gmod_language to another language
local selectedLanguage = "en" -- Switch language by setting gmod_language to another language
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think even if the convar is empty, we should still try to use it. That way it will still work if some other server managed to configure it differently.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'll revert this back too.

@jjyao88
Copy link
Contributor Author

jjyao88 commented Jul 18, 2024

Thanks for the PR! I have to be honest, this is the first time I hear of this bug, and the language system has not changed in a long time. I think perhaps there may be something off in your setup. Maybe your server.cfg sets it, but some other config or script unsets it.

To confirm this, I have reinstalled the dedicated server on my non-English Windows. Despite only enabling DarkRP and my language file and setting my server.cfg, in-game notifications are still appearing in English.

@FlorianLeChat
Copy link
Contributor

I've been running a French DarkRP server for a decade and have strangely never experienced this issue, is your dedicated server on the stable branch or on a development branch?

@jjyao88
Copy link
Contributor Author

jjyao88 commented Jul 18, 2024

I've been running a French DarkRP server for a decade and have strangely never experienced this issue, is your dedicated server on the stable branch or on a development branch?

I'm using the stable branch. What operating system and locale does your server use?

@FlorianLeChat
Copy link
Contributor

My dedicated server uses Debian 12 configured in French. My Gmod server isn't virtualized or otherwise using Docker.

Protocol version 24
Exe version 2023.06.28 (garrysmod)
Exe build: 19:02:32 Mar 21 2024 (9246) (4000)
GMod version 2024.03.21, branch: unknown
Linux 32bit Dedicated Server

@@ -5,6 +5,14 @@ cvars.AddChangeCallback("gmod_language", function(cv, old, new)
selectedLanguage = new
end)

hook.Add("Think", "DarkRPSetLanguage", function()
gmodLanguage = GetConVar("gmod_language"):GetString()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that this introduces a new global variable, by the way.

@FPtje
Copy link
Owner

FPtje commented Jul 25, 2024

The language setting probably works for most people without this pull request, since @FlorianLeChat mentioned it working for them. However, I also think this workaround is harmful for those where it does not work. I just pushed some changes, so this is good for merging.

Thanks!

@FPtje FPtje merged commit ae5ccfc into FPtje:master Jul 25, 2024
2 checks passed
@jjyao88 jjyao88 deleted the fix/localization branch July 25, 2024 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants