STCMS Documentation
Complete guide to building modern, secure React/PHP applications with STCMS framework
Multi-Language Support
Complete guide to implementing multi-language support in STCMS
Language Detection
STCMS automatically detects language from URL patterns:
- •
/en/
- English - •
/de/
- German - •
/fa/
- Persian (RTL) - •
/ar/
- Arabic (RTL)
Environment Configuration
File: .env
API_BASE_URL=http://localhost:80
CACHE_DRIVER=apcu
DEFAULT_LANGUAGE=en
Set your default language in the environment file. The router will use this as fallback.
Router Configuration
File: index.php
// Configure supported languages
$router = new MultilingualRouter(['en', 'de', 'fa', 'ar']);
// The router automatically reads DEFAULT_LANGUAGE from .env
// and uses it as fallback for invalid languages
Add your supported languages to the router array. Invalid languages will fall back to the default.
Template Implementation
Language-Specific Content
<h1>Welcome to STCMS</h1>
<p>Hybrid PHP/React Content Management System</p>
Use the lang
variable to conditionally display content based on the current language.
File Structure
pages/
├── en/ # Default language (from .env)
│ ├── index.twig
│ ├── about.twig
│ └── contact.twig
├── de/ # German
│ ├── index.twig
│ ├── about.twig
│ └── contact.twig
├── fa/ # Persian
│ ├── index.twig
│ ├── about.twig
│ └── contact.twig
└── ar/ # Arabic
├── index.twig
├── about.twig
└── contact.twig
Organize your templates by language in separate folders under pages/
.
Language Switching
JavaScript Implementation
function switchLanguage(newLang) {
const currentPath = window.location.pathname;
const pathWithoutLang = currentPath.replace(/^\/(en|de|fa|ar)\//, '/');
const newUrl = '/' + newLang + pathWithoutLang;
window.location.href = newUrl;
}
Implement language switching in your frontend to allow users to change languages.
RTL Language Support
HTML Template
<body >
<!-- Your content here -->
</body>
Set the dir
attribute for RTL languages like Persian and Arabic.
URL Examples
How URLs Work
URL | Language | Template |
---|---|---|
/ |
en (default) | en/index.twig |
/en/about |
en | en/about.twig |
/de/contact |
de | de/contact.twig |
/fa/ |
fa | fa/index.twig |
/invalid/page |
en (fallback) | en/page.twig |
The router automatically detects language from URL and falls back to default for invalid languages.
Multi-Language Best Practices
- • Start with one language and add others gradually
- • Use consistent naming for files across languages
- • Test all languages before deployment
- • Consider cultural differences in content and layout
- • Use professional translation for important content
- • Implement language detection based on user preferences