TextChatMessage.Translation is empty when using string.format

To reproduce this turn on automatic chat translation and use string format on client OnIncomingMessage function: string.format("<font color='rgb(100, 225, 100)'>%s</font>", textChatMessage.Translation).

image
image
image

Expected behavior

Translation should appear when string is formatted.

2 Likes

Thanks for the report! I filed a ticket in our internal database and we’ll follow up when we have an update for you.

Hi Lvie! Is this from Studio? Unfortunately, the translation field is not populated when testing inside Studio, however it should work when you test it inside a live session with another player.

I tested this in a private server.

Ah it looks like there’s a bug with the example code since the translation can be an empty string and not just nil when it doesn’t exist, it should be:

local TextChatService = game:GetService("TextChatService")

local FONT_COLOR = "#FF007F"
local FORMAT_STRING = `<font color='{FONT_COLOR}'>%s</font>`

local function onIncomingChatMessage(textChatMessage: TextChatMessage)
	local properties = Instance.new("TextChatMessageProperties")

	properties.Text = string.format(FORMAT_STRING, textChatMessage.Text)
	
	if textChatMessage.Translation ~= nil and textChatMessage.Translation ~= "" then
		properties.Translation = string.format(FORMAT_STRING, textChatMessage.Translation)
	end

	return properties
end

TextChatService.OnIncomingMessage = onIncomingChatMessage

I’ll put in an update to the docs to reflect this. Let me know if this fix resolves your problem!

1 Like

Hey I tried that solution too before and only now it works. I’ll use the string.len() == 0 method, thanks.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.