Text Formatter - HB-Hridoy/th-m-l-t GitHub Wiki
This guide explains how to format text in your app to enable dynamic translation and styling with the ThMLT extension for AI2.
📌 Overview
ThMLT enables smart formatting of text views by scanning for special syntax patterns inside your layout. These patterns are interpreted as formatting instructions based on the active language and theme mode.
🧠 Format Pattern Syntax
To format a text view using ThMLT, structure your text like this:
[tag1,tag2,tag3]Your Visible Text Here
✅ Example
[name,regular,label]Welcome Back!
Here’s how it breaks down:
name
→ Translation keyregular
→ Font tag (must match the shortFontTag from Fonts JSON)label
→ Color key (must exist in the Semantic color map)Welcome Back!
→ The fallback/default visible text
🛠️ How the Formatting Works
- The
ApplyFormattingTo
block looks inside the layout for any text views. - It parses each view’s text for the bracketed format.
- It replaces the text using values from your translation, font, and theme configuration.
🔍 Behavior Notes
- If translation for
name
isn’t found, the visible text fallback is used. - If the font tag is invalid or not found, the default font will be applied.
- If the color key isn’t found in the current theme mode, a fallback color is used.
⚠️ Tips for Reliable Formatting
- Always include fallback visible text after the bracketed section.
- Make sure the
Fonts
andColor Theme
JSON files are properly initialized and valid. - Avoid using reserved tags or malformed bracket syntax.
🧪 Debugging
If you don’t see the correct formatting:
- Check if the screen has been initialized with the ThMLT
Initialize
block. - Validate your JSON structures using the validator.
- Inspect your text formatting for correct bracket syntax.