7 - multi languages oop class text translations

Preview
1 min
4 min read

Multi-Language OOP Class Text Translations in PHP (Full Practical Guide for Real Business Applications)

Building multilingual websites is one of the most important requirements for modern businesses. Whether you're creating an e-commerce store, SaaS dashboard, CRM system, LMS platform, or even a simple company website, your users expect to browse your platform in their own language.

In this lesson, we explore how to build a complete OOP-based multi-language translation system in PHP, similar to what large companies use before integrating advanced frameworks. This tutorial is practical, simple, and perfect for real-life projects.


Why Every Modern Web Application Needs Multi-Language Support

Supporting more than one language is no longer optional. Today, it represents:

  • A competitive advantage in SEO for global search traffic
  • Higher conversion rates because users trust websites in their local language
  • Better user experience across mobile and desktop devices
  • International expansion for SaaS, LMS, and online services
  • Accessibility and inclusivity to reach millions of new users

This is why companies like Amazon, AliExpress, Coursera, and Airbnb invest heavily in multi-language systems. In this lesson, you build the foundation of such systems from scratch.


What You Will Learn in This Lesson

This lesson takes you step-by-step through implementing a PHP OOP translation engine that supports:

  • Multiple languages (Arabic, English, German)
  • Auto-detecting the current page
  • Loading the correct language file dynamically
  • Using cookies to store the user’s preferred language
  • Reusable transe() function for printing translations easily
  • Organizing translations per page (index.php, products.php, add_product.php)

Understanding the Folder Structure

2-multi-langs/
│
├── index.php
├── products.php
├── add_product.php
│
├── includes/
│   ├── header.php
│   ├── footer.php
│   └── Language.php
│
└── languages/
    ├── en/
    │   ├── index.php
    │   ├── add_product.php
    │   └── products.php
    ├── ar/
    │   ├── index.php
    │   ├── add_product.php
    │   └── products.php
    └── de/
        ├── index.php
        ├── add_product.php
        └── products.php

This clear structure allows you to scale your app to 10, 20, or even 100 languages without modifying much code.


The Heart of the System: Language.php Class

The Language class handles:

  • Loading the selected language from cookies
  • Loading the correct file for each page
  • Returning the translated string

The class extracts the page name automatically using:


$this->path = basename($_SERVER['PHP_SELF'], '.php');

So if the user is on index.php, the system loads:

languages/en/index.php
languages/ar/index.php
languages/de/index.php

Everything is automatic.


How the Translation Files Work

Each page has its own translation file. Example:

<?php
$localization = array();
$localization['__email__'] = 'Email address';
$localization['__password__'] = 'Password';
$localization['__submit__'] = 'Submit';
return $localization;

Each key is unique, short, and used in the design level:

<?php transe('__email__'); ?>

This is easy to maintain and fast to load.


The Global transe() Function

To make translation calls simple inside HTML, the system uses a function wrapper:


function transe($string) {
    echo Language::transe($string);
}

Now your HTML becomes clean and readable:


<label><?php transe('__pr_name__'); ?></label>
<input type="text" placeholder="<?php transe('__pr_name__'); ?>">

The Language Switcher (setcookie.php)

Users can change languages using simple links:


setcookie('language', $_GET["lang_set"], time() + 3600 );
header("Location: ".$_SERVER["HTTP_REFERER"]);

This instantly reloads the page in the new language.


Real-Life Business Applications for This System

This multi-language system can be used in huge real-world scenarios, including:

1. E-Commerce Websites

  • Product name translations
  • Labels for forms (price, quantity, add to cart)
  • Checkout system translations
  • Notifications: “Order Received”, “Payment Successful”, etc.

2. SaaS Applications

  • User dashboards
  • Settings panel
  • Multi-language invoices
  • Company onboarding content

3. LMS / Education Platforms

  • Course titles
  • Lessons
  • Certificates
  • Student instructions

4. Booking and Travel Websites

  • Hotel descriptions
  • Room features
  • Search filters
  • Payment confirmation messages

Your simple OOP class can scale to serve millions of users per day.


This lesson provides a complete working solution with:

  • Directory structure
  • OOP class
  • Dynamic translation loader
  • Real code examples
  • Best practices for scalability

Final Thoughts

By building this multi-language OOP class, you are learning a real-world skill used in every professional software company. This system is lightweight, scalable, and can be integrated into any PHP project—plain PHP, WordPress themes, custom CMS, or even Laravel (as a concept).

Keep learning — your skills can build products used by millions.

PHP & OOP & MySQLi & PDO

PHP & OOP & MySQLi & PDO

php website
softwarePHPWeb Development Basics
View course

Course Lessons