Trongate PHP Framework Docs
Introduction
Basic Concepts
Understanding Routing
Intercepting Requests
Module Fundamentals
Database Operations
Templates
Helpers
Form Handling
Form Validation
Working With Files
Image Manipulation
Working With Dates & Times
Language Control
Authorization & Authentication
Tips And Best Practices

Loading Language Files

Trongate allows you to maintain a clean, professional application by separating your logic from your static text. The framework does not impose a single global file; instead, it encourages a structured directory system based on the principle of one subdirectory per language.


The Directory Protocol

To support multiple languages, you must create a dedicated subdirectory for every language your application supports. These directories are named using standard language codes (e.g., en, fr, es).

A typical structure within a module looks like this:

  • modules/contact/language/en/phrases.php
  • modules/contact/language/fr/phrases.php
  • modules/contact/language/es/phrases.php

The load() Method

The load() method is used to fetch the translation array from the correct subdirectory. To ensure your code remains dynamic, use the {lang} placeholder:


Multi-Language Example: Thank You Page

In this scenario, we define the text for English, French, and Spanish. Notice that the language file must define an array named $phrases.

1. Language Files

English (en/phrases.php):

French (fr/phrases.php):

Spanish (es/phrases.php):


Controller and View (Separation of Concerns)

The controller prepares clean, simple variables for the view. This ensures the view is "dumb" and strictly concerned with output.

The Controller

The View

By mapping language strings to specific variables in the controller, you create a clear contract between your logic and your display. This makes your code more readable, safer, and easier to maintain.