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

Automatic Language Detection

STCMS automatically detects language from URL patterns:

/en/ English
/de/ German
/fa/ Persian (RTL)
/ar/ Arabic (RTL)
info: Languages are auto-detected from folder structure in /pages directory - no manual configuration needed!

1 Environment Configuration

Environment Variables
API_BASE_URL=http://localhost:80
CACHE_DRIVER=apcu
DEFAULT_LANGUAGE=en
Tip: Set DEFAULT_LANGUAGE in .env - the router uses this as fallback for invalid languages.

2 Router Configuration

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
info: Add your supported languages to the router array. Invalid languages fall back to default.

3 File Structure

Language Folder Structure
pages/
├── en/                    # Default language (from .env)
│   ├── index.twig
│   ├── about.twig
│   └── contact.twig
├── de/                    # German
│   ├── index.twig
│   ├── about.twig
│   └── contact.twig
├── fa/                    # Persian (RTL)
│   ├── index.twig
│   └── about.twig
└── ar/                    # Arabic (RTL)
    └── index.twig
Tip: Simply create a new folder (e.g., pages/fr/) to add French - it is auto-detected!

4 Language-Specific Content

Conditional Content
{% if lang == 'de' %}
    <h1>Willkommen bei STCMS</h1>
    <p>Hybrides PHP/React Content Management System</p>
{% elseif lang == 'fa' %}
    <h1>به STCMS خوش آمدید</h1>
    <p>سیستم مدیریت محتوای هیبریدی PHP/React</p>
{% else %}
    <h1>Welcome to STCMS</h1>
    <p>Hybrid PHP/React Content Management System</p>
{% endif %}
info: Use the "lang" variable to display content based on current language.

5 Language Switching

Language Switcher
function switchLanguage(newLang) {
    const currentPath = window.location.pathname;
    const pathWithoutLang = currentPath.replace(/^\/(en|de|fa|ar)\//, '/');
    const newUrl = '/' + newLang + pathWithoutLang;
    window.location.href = newUrl;
}

// Usage: switchLanguage('de')
Tip: This keeps users on the same page when switching languages.

6 RTL Language Support

RTL Direction
<body {% if lang in ['fa', 'ar'] %}dir="rtl"{% endif %}>
    <!-- Your content here -->
</body>
info: Set dir="rtl" for right-to-left languages like Persian and Arabic.

URL Routing Examples

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

Multi-Language Best Practices

Start Simple Begin with one language and add others gradually
Consistent Naming Use same file names across all languages
Test All Languages Verify all languages work before deployment
Cultural Awareness Consider cultural differences in content and layout
Professional Translation Use professional translation for important content
User Preferences Implement language detection based on browser settings