HTML Language Attributes
The Language module determines which language your application is using.
It does not automatically modify your HTML.
This is by design.
You remain in full control of how language is expressed in your markup.
The <html lang=""> Attribute
Most developers are familiar with this:
This attribute tells browsers and assistive technologies what language the page is written in.
Should You Change It?
Yes - if your page content changes language.
If your application switches from English to French, your HTML should reflect that:
This ensures:
- Screen readers use the correct pronunciation rules
- Search engines correctly index your content
- Browsers apply appropriate language-specific behaviour
The <meta charset> Tag
You will often see this in the <head> section:
Do You Need to Change This?
In almost all cases: No.
UTF-8 supports virtually all modern languages, including:
- English
- French
- Spanish
- Arabic
- Chinese
- Japanese
You should only consider changing the character set if:
- You are working with a legacy system
- You have a very specific encoding requirement
Otherwise, leave it as UTF-8.
Text Direction (LTR vs RTL)
Some languages are written from right to left (RTL), such as Arabic and Hebrew.
Modern browsers handle RTL text automatically when the lang attribute is correctly set. However, you may wish to explicitly declare the text direction to ensure consistent layout behaviour across all rendering engines and CSS frameworks.
Following the principle of Separation of Concerns, compute the direction in your controller:
Then render it cleanly in your view:
This ensures correct text flow and layout while keeping your view free of logic.
Other Useful HTML Language Attributes
1. lang on Individual Elements
You can override language for specific parts of a page:
This is useful when mixing languages within a single page.
2. hreflang (SEO)
Used in links to indicate alternate language versions:
This helps search engines understand multilingual content.
Putting It All Together
A typical multilingual HTML template might look like this:
Key Decisions (Quick Answers)
| Question | Answer |
|---|---|
| Should I change <html lang>? | Yes, when the page language changes |
| Should I change charset? | No, use UTF-8 in almost all cases |
| Do I need to handle text direction? | Only for RTL languages (e.g., Arabic, Hebrew) |
| Does Trongate do this automatically? | No - you remain in full control |
Why Trongate Leaves This to You
Many frameworks attempt to manage HTML language behaviour automatically.
This often leads to:
- Hidden behaviour
- Reduced flexibility
- Unexpected side effects
Trongate takes a different approach:
The framework handles state. You control output.
Separation of Concerns
Modules cannot be accessed directly from view files. Therefore, all language state must be resolved within your controller and passed as simple variables. This adheres to a strict Separation of Concerns - your view files remain "dumb," readable, and decoupled from the underlying module logic.
1. The Controller
Fetch the language once and pass it into the $data array:
2. The View
Your view remains clean, focusing only on the data it has been given:
Regarding Separation of Concerns
Keep your views strictly for presentation. Let the controller handle the logic of fetching the state, and let the view simply render the properties it receives. This ensures your code remains clean, independent, and professional.