RichTextLabel and KEYs to a .csv

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Mezkino

Hi there
I am using a .csv for managing my language options. Mostly I am using “labels” that are able to handle the keywords of the .csv.

But in some cases I would like to add some format to that text, so my question is if there is a way of using RichTextLabel with this keyword.

Thanks :slight_smile:

:bust_in_silhouette: Reply From: Mezkino

Still, when I place a keyword from the .csv in text or in the bb_text in the editor, it is not working, but it does from code.

self.bbcode_text = tr(text)

it even recognize bb_code from the .csv :slight_smile:

this is still happen!

Arthur T Ramos | 2020-01-06 20:04

:bust_in_silhouette: Reply From: JimArtificer

To achieve this you will need a script to call the tr() function on the translation keyword.

One way to do this would be to attach a script that defines an exported string property that is then run through the translation function and assigned to the text field.

This is a C# example, but you should be able to convert it to GDScript pretty easily:

public class TranslatedRichTextLabel : RichTextLabel {
	public string TrKey; //enter your translation key in the editor

	public override void _Ready() {
		BbcodeText = Tr(TrKey);

For simplicity you may want to write a separate script for a standard label, but you could also detect the node type to determine which text property should be assigned to.