chat: name a line's language in the client's locale (#2997)

A localized client tagged its own race's speech with a language header, so Say showed `[Common]` on a zhCN client.

The stock chat frame draws the header when the line's language name differs from `GetDefaultLanguage()` (`ChatFrame.lua:1442`). Both names come from `Languages.dbc`, in the locale's column (benilla-re `systems/ui/chatlanguage.md`). We answered `GetDefaultLanguage()` from the DBC but passed each line's language from a hard-coded English table, so the two never matched outside enUS.

The line's language is now named from the same `Languages.dbc` rows, and the English table is gone.

Test: `a_line_names_its_language_in_the_locale` gives a monster line language 7 with a zhCN row and checks `arg3` is that name; without the fix it reads `Common`.

Fixes #2996

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sam Sung
2026-11-06 20:41:24 +07:00
committed by GitHub
parent 63167449d8
commit 36ffde560e
5 changed files with 55 additions and 24 deletions
@@ -318,3 +318,29 @@ fn the_channel_lookups_read_the_slots_at_the_call() {
"the copy holds none"
);
}
/// A line's language reaches Lua as its `Languages.dbc` name in the client's locale, the name
/// `GetDefaultLanguage()` also answers, so a localized client's stock header test sees its own
/// tongue and draws no `[Language]` tag.
#[test]
fn a_line_names_its_language_in_the_locale() {
let mut c = client();
c.app
.world_mut()
.insert_resource(crate::ui_unit::LanguagesRes(
benilla_formats::Languages::from_rows(&[(7, "通用语")]),
));
c.eval::<()>(
false,
r#"Lang = nil
local g = CreateFrame("Frame")
g:RegisterEvent("CHAT_MSG_MONSTER_SAY")
g:SetScript("OnEvent", function() Lang = arg3 end)"#,
);
let mut line = boar_says("hi");
if let SessionEvent::Chat(m) = &mut line {
m.language = 7;
}
c.frame(vec![vec![line]]);
assert_eq!(c.eval::<String>(false, "return Lang"), "通用语");
}
-22
View File
@@ -674,25 +674,3 @@ pub(crate) fn flag_of_tag(chat_tag: u8) -> &'static str {
_ => "",
}
}
/// The 1.12 language names by wire id (vmangos `SharedDefines.h`, `LANG_*`), for the `[Language]`
/// header. Language 0 has no `Languages.dbc` row, so the stock `arg3 ~= "Universal"` test never
/// fires: an empty arg3 is what suppresses the header (`ChatFrame.lua:1442`).
pub(crate) fn language_name(id: u32) -> &'static str {
match id {
1 => "Orcish",
2 => "Darnassian",
3 => "Taurahe",
6 => "Dwarvish",
7 => "Common",
8 => "Demonic",
9 => "Titan",
10 => "Thalassian",
11 => "Draconic",
12 => "Kalimag",
13 => "Gnomish",
14 => "Troll",
33 => "Gutterspeak",
_ => "", // 0, Universal, and unknown ids: no header
}
}
+2 -2
View File
@@ -14,7 +14,7 @@ use crate::names::NameCache;
use crate::net::{GuidIndex, NetCommands, ObjectStore, SelfGuid};
use super::edit::ChannelState;
use super::event::{flag_of_tag, kind_of_wire, language_name, ChatEvent, ChatEventKind};
use super::event::{flag_of_tag, kind_of_wire, ChatEvent, ChatEventKind};
use super::frames::{route, ChatWindows};
use crate::query_cache::Ask;
@@ -1927,7 +1927,7 @@ fn fire_one(
}),
// The effective language, not the wire's: narration types and GM mode force
// 0, which also drops the `[Language]` header.
language: language_name(language).to_string(),
language: langs.language_name(language),
channel: channel_base,
flag: flag_of_tag(msg.chat_tag).to_string(),
..Default::default()
@@ -47,6 +47,8 @@ impl ChatLanguages {
/// skill per language, the GM bit and whether a local player is held at all.
pub(crate) struct Gate<'a> {
words: Option<&'a LanguageWords>,
/// `Languages.dbc` at the client's locale, which names a line's language to Lua.
names: Option<&'a benilla_formats::Languages>,
/// language id → this character's skill in it. Absent = 0 = never understood.
skill: HashMap<u32, u32>,
/// `PLAYER_FLAGS & 0x8`: a GM reads every line plain, with no `[Language]` header.
@@ -56,6 +58,17 @@ pub(crate) struct Gate<'a> {
}
impl Gate<'_> {
/// The line's language as Lua reads it, `arg3`: its `Languages.dbc` name in the client's
/// locale, which is also what `GetDefaultLanguage()` answers, so the stock header test
/// (`arg3 ~= this.defaultLanguage`, `ChatFrame.lua:1442`) compares like with like. Language 0
/// has no row, so it is empty and draws no header.
pub(crate) fn language_name(&self, language: u32) -> String {
self.names
.and_then(|n| n.name(language))
.unwrap_or_default()
.to_string()
}
/// This character's skill in `language`, the second argument of `0x49b560`.
pub(crate) fn skill(&self, language: u32) -> u32 {
self.skill.get(&language).copied().unwrap_or(0)
@@ -136,6 +149,8 @@ pub(crate) struct LanguageReads<'w, 's> {
actions: Option<Res<'w, PlayerActions>>,
spells: Option<Res<'w, Spells>>,
skill_lines: Option<Res<'w, SkillLines>>,
/// The language names; absent without an install, where a line's language is unnamed.
names: Option<Res<'w, crate::ui_unit::LanguagesRes>>,
me: Query<'w, 's, &'static ObjectStore, With<SelfPlayer>>,
}
@@ -146,10 +161,12 @@ impl LanguageReads<'_, '_> {
/// `PLAYER_SKILL_INFO` value.
pub(crate) fn gate(&self) -> Gate<'_> {
let words = self.langs.as_deref().and_then(|l| l.words.as_ref());
let names = self.names.as_deref().map(|n| &n.0);
let Ok(store) = self.me.single() else {
// No body: every line renders plain.
return Gate {
words,
names,
skill: HashMap::new(),
gm: false,
have_player: false,
@@ -176,6 +193,7 @@ impl LanguageReads<'_, '_> {
}
Gate {
words,
names,
skill,
gm: store.0.player_flags() & PLAYER_FLAGS_GM != 0,
have_player: true,
@@ -272,6 +290,7 @@ mod tests {
fn langs(skill: &[(u32, u32)], gm: bool) -> Gate<'static> {
Gate {
words: None,
names: None,
skill: skill.iter().copied().collect(),
gm,
have_player: true,
+8
View File
@@ -85,6 +85,14 @@ impl Languages {
.filter_map(|(id, name)| Some((*id, name.as_deref()?)))
}
/// The name of the row whose id is `id`, in the locale's column; `None` with no such row.
pub fn name(&self, id: u32) -> Option<&str> {
self.0
.iter()
.find(|(row, _)| *row == id)
.and_then(|(_, name)| name.as_deref())
}
pub fn len(&self) -> usize {
self.0.len()
}