-
-
Notifications
You must be signed in to change notification settings - Fork 0
Texts
Yannik Höflich edited this page Sep 3, 2023
·
1 revision
For supporting simple translations of the web interface, MatrixWeb has the Text
class. You can find all supported languages at LanguageConfig
One Text
is build from multiple TextElement
.
Example
TextElement englishTextElement = new TextElement(LanguageCode.EN, "english text");
TextElement germanTextElement = new TextElement(LanguageCode.DE, "deutscher text");
Text text = new Text(englishTextElement, germanTextElement);
There is also an implicit cast from string to Text. If you use that, the string will be the translation in all languages.
Text fromString = "This is a test text";
// Is the same as:
Text fromConstructor = new Text(new TextElement(LanguageCode.EN, "This is a test text")
new TextElement(LanguageCode.DE, "This is a test text"));
MatrixWeb will select the configured language out of the Text with the TextService
. You can use it yourself too.
public class ExampleService{
private Text _exampleText = new Text(new TextElement(LanguageCode.EN, "english text"),
new TextElement(LanguageCode.DE, "deutscher text"));
private TextService _textService;
public ExampleService(TextService textService){
_textService = textService;
}
public string GetText(){
return _textService.GetTranslation(_exampleText);
}
}