“PHP Multilanguage Class (PHPMLC)” Documentation by “Övünç Tükenmez” v1.5.3


“PHP Multilanguage Class (PHPMLC)”

Created: 12.08.2014
Last Update: 16.02.2019
By: Ovunc Tukenmez
Email: [email protected]

Thank you for purchasing this PHP class. If you have any questions that are beyond the scope of this help file, please feel free to email via my user page contact form here or just send me an email. Thanks!


Table of Contents

  1. Class
    1. Class Info
    2. Used Technologies
    3. Live Demo
    4. Change Log
  2. Installation
    1. Requirements
    2. Installation Process
  3. Admin Panel Usage
    1. Login
    2. Changing Access Credentials
    3. Managing Panel Languages
    4. Managing Panel Translations
    5. Managing Languages
    6. Managing Translations
  4. Class Usage
  5. Sources and Credits
  6. Recommended Projects

1. Class - top

1.1. Class Info - top

PHP Multilanguage Class (PHPMLC) is a PHP class that is used to implement multilanguage feature to the websites/softwares.
It comes with administration panel where the user can manage translated strings.
All translation data is stored in the MYSQL database.
Translation key is used to get the translated string value.


1.2. Used Technologies - top

The following technologies and libraries are used in the PHPMLC:


1.3. Live Demo - top

It is possible to see live demo with the following links:

⇒ Sample Welcome Message:
http://www.jetphp.com/php_multilanguage_class/example.php

⇒ Admin Panel:
http://www.jetphp.com/php_multilanguage_class/ml_admin/
Please use following credentials to access the admin panel.
username: admin
password: password
Please note the admin panel demo is read-only for the security purposes.


1.4. Change Log - top

v1.0.0

v1.1.0 v1.5.0 v1.5.1 v1.5.2 v1.5.3


2. Installation - top

2.1. Requirements - top

PHPMLC requires the following software in order to run:


2.2. Installation Process - top

Folder Structure:
The folder structure of the "Multilanguage" folder is as follows:
Folder Structure
Navigate "code" folder and you will see "PHPMLC" folder and "example.php"
If you look the source code of the "example.php", you can understand that the php multilanguage class exists in the "PHPMLC/class" folder.
The files of the administation panel can be found in the "PHPMLC/ml_admin" folder.

Setting up the Database:
First create new database in your MySQL server. (You can give it the name "multilanguage").
Note: If you are on shared host, generally you create database using hosting provider's admin panel.
If you have create database rights, you can also use phpMyAdmin.

Once you have created database, you are ready to create tables.
To create tables, please find "database.txt" file within "installation and documentation" folder.
database.txt
Copy all its contents and execute it using phpMyAdmin panel.
After the execution, table list should like the following: (for the version 1.1.0) Table list

If you want to import demo data, please find "demo-content.txt" file within "installation and documentation" folder.
demo-content.txt
Copy all its contents and execute it using phpMyAdmin panel.

Setting up Configuration:
After you create database and create database tables, you need to configure your database access settings.
Open "config/database.php" from "code/PHPMLC/class" folder.
Its contents should look like the following:
config/database.php
Change the values according to your settings.
$conn_host: database host url (generally "localhost")
$conn_database: database name (if you followed this documentation, will be "multilanguage")
$conn_user: database user name
$conn_password: database user password

Setting up File Modes:
In order to the panel can work without errors, you should give write permissions to the following files and folders:
- "PHPMLC/ml_admin/access_credentials.php"
Just set file mode to "0755" using ftp software or using control panel of your hosting provider.
If you want, you can just execute "set_file_modes.php" located in the "PHPMLC/ml_admin" folder.
set_file_modes.php


3. Admin Panel Usage - top

3.1. Login - top

In order to access admin panel, visit "your_code_folder/PHPMLC/ml_admin" page.
Default access credentials are as following:
username: admin
password: password
Admin Panel Login Page
Once you entered correct access credentials, you will be redirected to the "Welcome Page". Admin Panel Welcome Page


3.2. Changing Access Credentials - top

Click to the "Edit Access Credentials" link from the menu.
Admin Panel Edit Access Credentials
Change the values and click "Save".
In your next login, you will need to use the new access credentials.


3.3. Managing Panel Languages - top

Click to the "Languages (Panel)" link from the menu.
Admin Panel Languages Page

Creating New Panel Language:
To create new language, use the form located top of the "Languages (Panel)" page.
Language: Enter the native language name.
Language Code: Enter 2 character language code. (You can access the "List of ISO 639-1 codes" with this link.)
Display Order: The languages are fetched from the database by the display order and the language name. Valid value range is 0-255.
Is default?: If you want to set this language as the panel language, check this value.
Click "Insert" to save the language.

Admin Panel Language List

Editing A Panel Language:
To edit a panel language, use the "Edit" link within the "Languages (Panel)" page.
Language edit form will be shown.
Make the desired changes and click "Save".

Deleting A Panel Language:
To delete a language, use the "Delete" link within the "Languages (Panel)" page.
Once you agree that you want to delete the record, the language record will be marked as "deleted".
Note: If you accicentally deleted a record, you can revert it back by setting its "is_deleted" value to "0" using "phpMyAdmin".
Please also note that if there is only one language in the database, the delete action will be cancelled.


3.4. Managing Panel Translations - top

Click to the "Translations (Panel)" link from the menu.
Admin Panel Translations

Creating New Panel Translation:
To create new translation, use the form located top of the "Translations (Panel)" page.
Key: Enter the translation key. (You will use this key to get translated string.)
Value: Enter the translated string for each language.
Click "Insert" to save the translation.

Admin Panel Translations List

Editing A Panel Translation:
To edit a panel translation data, make desired changes on the translations for each languages and click "Save" button that is located on bottom of the page.


3.5. Managing Languages - top

Click to the "Languages" link from the menu.
Admin Languages Page

Creating New Language:
To create new language, use the form located top of the "Languages" page.
Language: Enter the native language name.
Language Code: Enter 2 character language code. (You can access the "List of ISO 639-1 codes" with this link.)
Display Order: The languages are fetched from the database by the display order and the language name. Valid value range is 0-255.
Is default?: If you want to set this language as the default language, check this value. (if the "autoSelectCurrentLanguage()" method can't find suitable language, it will switch to the default language.)
Click "Insert" to save the language.

Admin Language List

Editing A Language:
To edit a language, use the "Edit" link within the "Languages" page.
Language edit form will be shown.
Make the desired changes and click "Save".

Deleting A Language:
To delete a language, use the "Delete" link within the "Languages (Panel)" page.
Once you agree that you want to delete the record, the language record will be marked as "deleted".
Note: If you accicentally deleted a record, you can revert it back by setting its "is_deleted" value to "0" using "phpMyAdmin".
Please also note that if there is only one language in the database, the delete action will be cancelled.


3.6. Managing Translations - top

Click to the "Translations" link from the menu.
Admin Translations

Creating New Translation:
To create new translation, use the form located top of the "Translations" page.
Key: Enter the translation key. (You will use this key to get translated string.)
Value: Enter the translated string for each language.
Click "Insert" to save the translation.

Admin Translations List

Editing A Translation Key:
To edit a translation key, use the "Edit" link within the "Translations" page.
Translation Key edit form will be shown.
Make the desired changes and click "Save".

Deleting A Translation:
To delete a translation, use the "Delete" link within the "Translations" page.
Once you agree that you want to delete the record, the language record will be marked as "deleted".
Note: If you accicentally deleted a record, you can revert it back by setting its "is_deleted" value to "0" using "phpMyAdmin".


4. Class Usage - top

Adding class file:
Adding class file

Initializing class:
Initializing class

"autoSelectCurrentLanguage()" method usage:
When the class initialized, the "autoSelectCurrentLanguage()" method is automatically called. By default, the "autoSelectCurrentLanguage()" method looks if the $_GET['lang'] is defined. If you want to use other key than "lang", call the "autoSelectCurrentLanguage()" method with its parameter.
autoSelectCurrentLanguage() method usage

"setCurrentLanguage()" method usage:
It is possible to select language with "setCurrentLanguage()". It takes language code as the first parameter.
Boolean value is returned.
setCurrentLanguage() method usage

"getCurrentLanguageCode()" method usage:
It is possible to get current language code by calling "getCurrentLanguageCode()" method.
null or string is returned.
getCurrentLanguageCode() method usage

"getCurrentLanguageId()" method usage:
It is possible to get current language id by calling "getCurrentLanguageId()" method.
null or integer is returned.
getCurrentLanguageId() method usage

"getTranslationKeys()" method usage:
It is possible to get all translation keys by calling "getTranslationKeys()" method.
array is returned.
Item keys: id, label
getTranslationKeys() method usage

"getLanguages()" method usage:
It is possible to get all available languages by calling "getLanguages()" method.
null or array is returned.
Item keys: id, name, language_code, display_order, is_default
getLanguages() method usage

"getLanguageIds()" method usage:
It is possible to get all available language ids by calling "getLanguageIds()" method.
null or array is returned.
Item format: "language_code" => id
getLanguageIds() method usage

"getTranslatedStringsForCurrentLanguage()" method usage:
To get all translated strings for the currently selected language, simply call "getTranslatedStringsForCurrentLanguage()" method.
array is returned.
Item format: "translation key" => translated string
getTranslatedStringsForCurrentLanguage() method usage

"getTranslatedString()" method usage:
To get the translated string for the specific key, you can use "getTranslatedString()" method.
First parameter takes translation key. Optional second parameter takes language code. If the second parameter is not given, translated string for the currently selected language will be returned.
string is returned.
Item format: "translation key" => translated string
getTranslatedString() method usage

Other methods:
All public methods of the class are commented.


5. Sources and Credits - top

I've used the following images, icons, libraries or other files as listed.


6. Recommended Projects - top


Once again, thank you so much for purchasing PHP Multilanguage Class (PHPMLC). As I said at the beginning, I'd be glad to help you if you have any questions relating to this PHP class. No guarantees, but I'll do my best to assist. For any kind of bug reports, feedback, feature requests, or even if you just want to say hello, feel free to email me. I'll be really happy about it.

Ovunc Tukenmez

Go To Table of Contents