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


“PHP Multilanguage Class (PHPMLC)”

Last Update: 06.06.2021
By: Ovunc Tukenmez
Email: ovunct@live.com

Thank you for purchasing this PHP class. If you have any question that is beyond the scope of this help file, please feel free to send me an email. Thanks!


Table of Contents

  1. Class
    1. Class Info
    2. Used Technologies
    3. Live Demo
  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. Video Demonstration of a Sample Translation Process
  6. Sources and Credits

1. Class - top

1.1. Class Info - top

PHP Multilanguage Class (PHPMLC) is a PHP class to implement multilanguage feature to the websites/apps.
The class database contains 111 languages and their cross translations.
It comes with administration panel to manage translations easily. The languages cane activated/deactivated using administration panel.
All translation data is stored in the SQLite database.
The class supports dynamic/on-the-fly translations where the data comes from database.
With the Google Translate API support, auto translations can be made.
User can trigger auto translation for the desired language within Administration panel.


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 and dynamic translations of colors:
https://www.jetphp.com/php_multilanguage_class/example.php

⇒ Admin Panel:
https://www.jetphp.com/php_multilanguage_class/PHPMLC/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.


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".
"code" folder also contains "translations.db" file which location is required by PHPMLC class construct method.
PHPMLC (php multilanguage class) exists in the "PHPMLC/class" folder.
The files of the administation panel can be found in the "PHPMLC/ml_admin" folder.
"PHPMLC/ml_admin" folder also contains "panel_translations.db" file which is used to store administration panel translations.

Setting up Configuration:
In order to administration panel works properly, ajax url and google translation api key should be set.
Open "code/PHPMLC/ml_admin/config/panel.php".
config/panel.php
Change the values with your settings:
config/panel.php

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
In this screen, you can activate/deactivate administration panel languages.
To set a language as a default panel language, click edit to open update form. Default language can't be deactivated.


3.4. Managing Panel Translations - top

Click to the "Translations (Panel)" link from the menu.
Admin Panel Translations
In this screen, you can create new translation key, update translations and also auto-translate using Google Translate API.


3.5. Managing Languages - top

Click to the "Languages" link from the menu.
Admin Languages Page
In this screen, you can activate/deactivate languages.
To set a language as a default language, click edit to open update form. Default language can't be deactivated.


3.6. Managing Translations - top

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

In this screen, you can create new translation key, update translations and also auto-translate using Google Translate API.


3.7. Managing Dynamic Translations - top

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

In this screen, you can update translations and also auto-translate using Google Translate API.
Dynamic translation keys are automatically generated when "getDynamic()" class method is called.


4. Class Usage - top

Adding class file:
Adding class file

Creating a new class instance:
Creating a new class instance

"setAutoCreateNonExistingKeys()" method usage:
When the "get()" method is called, if the key does not exist, the class will create if internal "$_auto_create_non_existing_keys" private property is true.
To change the value, "setAutoCreateNonExistingKeys()" method should be called with boolean parameter.
setAutoCreateNonExistingKeys() method usage

"setGoogleTranslateApiKey()" method usage:
To set Google Translate Api key, call "setGoogleTranslateApiKey()" method.
setGoogleTranslateApiKey() method usage

"init()" method usage:
"init()" method should be called to trigger initial setup.
autoSelectCurrentLanguage() method usage

"selectDefaultLanguage()" method usage:
To switch to the default active language, use "selectDefaultLanguage()" method.
selectDefaultLanguage() method usage

"setCurrentLanguage()" method usage:
To switch to another activated language, use "setCurrentLanguage()" method.
It takes language code as a parameter.
Boolean value is returned.
setCurrentLanguage() method usage

"getCurrentLanguage()" method usage:
To get currently selected language details call "getCurrentLanguage()" method.
if there is no selected language, the method returns null. otherwise, the method returns an array.
getCurrentLanguage() method usage

"getCurrentLanguageCode()" method usage:
To get the language code of the currently selected language, call "getCurrentLanguageCode()" method.
if there is no selected language, the method returns null. otherwise, the method returns string.
getCurrentLanguageCode() method usage

"getActiveLanguages()" method usage:
To get active language array, call "getActiveLanguages()" method.
getActiveLanguages() method usage

"getLanguageName()" method usage:
To get translation of a language code, call "getLanguageName()" method.
array is returned.
The method returns string. getLanguageName() method usage

"get()" method usage:
To get the translation of a key, call "get()" method.
String is returned.
get() method usage

"set()" method usage:
To set the translation of a key, call "set()" method.
Returns true on success, false on errors.
set() method usage

"getDynamic()" method usage:
To get the translation of a dynamic value, call "getDynamic()" method.
String is returned.
getDynamic() method usage

"delete()" method usage:
To delete a translation of a language, call "delete()" method.
Returns true on success, false on errors.
delete() method usage

"translate()" method usage:
To directly get the translation of a string using google translate service, call "translate()" method.
translate() method usage

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


5. Video Demonstration of a Sample Translation Process - top


6. Sources and Credits - top

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


Once again, thank you so much for purchasing PHP Multilanguage Class (PHPMLC). 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