From d7066f1faca31b1d3e28bdce23799564d560aa23 Mon Sep 17 00:00:00 2001 From: Tony Yao Date: Sun, 14 Jul 2024 14:43:40 +0800 Subject: [PATCH 1/5] fix: get `gmod_language` convar after game is loaded --- gamemode/modules/language/sh_language.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gamemode/modules/language/sh_language.lua b/gamemode/modules/language/sh_language.lua index cde8ba0da..c130f96c1 100644 --- a/gamemode/modules/language/sh_language.lua +++ b/gamemode/modules/language/sh_language.lua @@ -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 cvars.AddChangeCallback("gmod_language", function(cv, old, new) selectedLanguage = new end) +hook.Add("Think", "DarkRPSetLanguage", function() + gmodLanguage = GetConVar("gmod_language"):GetString() + if gmodLanguage != "" then + selectedLanguage = gmodLanguage + end + hook.Remove("Think", "DarkRPSetLanguage") +end) + function DarkRP.addLanguage(name, tbl) local old = rp_languages[name] or {} rp_languages[name] = tbl From 0db4ac06fbe70f5bb5140e2f90df2b609176e8b1 Mon Sep 17 00:00:00 2001 From: Tony Yao Date: Sun, 14 Jul 2024 17:41:56 +0800 Subject: [PATCH 2/5] fix: pose names aren't translated --- gamemode/modules/animations/sh_animations.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gamemode/modules/animations/sh_animations.lua b/gamemode/modules/animations/sh_animations.lua index 65b3a1315..152ec2037 100644 --- a/gamemode/modules/animations/sh_animations.lua +++ b/gamemode/modules/animations/sh_animations.lua @@ -1,7 +1,7 @@ local Anims = {} -- Load animations after the languages for translation purposes -hook.Add("loadCustomDarkRPItems", "loadAnimations", function() +hook.Add("Think", "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") @@ -11,6 +11,7 @@ hook.Add("loadCustomDarkRPItems", "loadAnimations", function() 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") + hook.Remove("Think", "loadAnimations") end) function DarkRP.addPlayerGesture(anim, text) From 7aede3bdbe59f766d73d1511ac2628774ec4dbc4 Mon Sep 17 00:00:00 2001 From: Tony Yao Date: Thu, 18 Jul 2024 13:32:52 +0800 Subject: [PATCH 3/5] Revert "fix: pose names aren't translated" This reverts commit 0db4ac06fbe70f5bb5140e2f90df2b609176e8b1. --- gamemode/modules/animations/sh_animations.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gamemode/modules/animations/sh_animations.lua b/gamemode/modules/animations/sh_animations.lua index 152ec2037..65b3a1315 100644 --- a/gamemode/modules/animations/sh_animations.lua +++ b/gamemode/modules/animations/sh_animations.lua @@ -1,7 +1,7 @@ local Anims = {} -- Load animations after the languages for translation purposes -hook.Add("Think", "loadAnimations", function() +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") @@ -11,7 +11,6 @@ hook.Add("Think", "loadAnimations", function() 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") - hook.Remove("Think", "loadAnimations") end) function DarkRP.addPlayerGesture(anim, text) From ffd6c9a33fa8252465dfe32065aa67792f27d5d0 Mon Sep 17 00:00:00 2001 From: Tony Yao Date: Thu, 18 Jul 2024 15:18:49 +0800 Subject: [PATCH 4/5] misc: revert selectedLanguage change --- gamemode/modules/language/sh_language.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gamemode/modules/language/sh_language.lua b/gamemode/modules/language/sh_language.lua index c130f96c1..6cbfdab77 100644 --- a/gamemode/modules/language/sh_language.lua +++ b/gamemode/modules/language/sh_language.lua @@ -1,5 +1,5 @@ local rp_languages = {} -local selectedLanguage = "en" -- Switch language by setting gmod_language to another language +local selectedLanguage = GetConVar("gmod_language"):GetString() -- Switch language by setting gmod_language to another language cvars.AddChangeCallback("gmod_language", function(cv, old, new) selectedLanguage = new From 4cee3c55c9bb35f863910fcc3054e96c289062ac Mon Sep 17 00:00:00 2001 From: Falco Peijnenburg Date: Thu, 25 Jul 2024 14:10:31 +0200 Subject: [PATCH 5/5] Fix introducing a local, and use a timer instead of Think --- gamemode/modules/language/sh_language.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gamemode/modules/language/sh_language.lua b/gamemode/modules/language/sh_language.lua index 6cbfdab77..b0097cae5 100644 --- a/gamemode/modules/language/sh_language.lua +++ b/gamemode/modules/language/sh_language.lua @@ -5,12 +5,13 @@ cvars.AddChangeCallback("gmod_language", function(cv, old, new) selectedLanguage = new end) -hook.Add("Think", "DarkRPSetLanguage", function() - gmodLanguage = GetConVar("gmod_language"):GetString() - if gmodLanguage != "" then +-- Some server owners experience that the language is not set correctly on +-- startup. This provides a failsafe in case that happens. +timer.Simple(0, function() + local gmodLanguage = GetConVar("gmod_language"):GetString() + if gmodLanguage ~= "" and selectedLanguage ~= gmodLanguage then selectedLanguage = gmodLanguage end - hook.Remove("Think", "DarkRPSetLanguage") end) function DarkRP.addLanguage(name, tbl)