Quick Guide

This quick guide will show you how to use and create it to master and master the tutorial.

Table of Contents


Includes: Provides different ones for you to choose and use.

Example 1: User-defined selection & Catalog

Steering after first run 'choose-country-region'Directory, select the language directory to match, with memory function.
Source: latest.zip -> /example/01-directory

Example 2: Loading files internally & Embedded

Automatically search for files in the matching directory. If no file is found, the default file is selected.
Source: latest.zip -> /example/02-embed

1. Create a matching language file under themes. E.g:


Embedded en-us.php files;


Embed zh-cn.php file;

See the files in the latest.zip->/example/02-embed/themes/homepage directory.

2. Create new page!

     Use template 02-embed/templets.php File, the user can change it to the new file name ( example: newpage.php ).

$lp = new lp();

$lp->masterCatalogue = "themes/{newpage}";


     Create directories and matching languages

Enter 02-embed/themes/newpage, the created directory must be consistent with the {newpage} variable name.

     Directory Structure


Example 3: Read the configuration file & Loading

Automatically search for matching language files and load them after loading, including: string characters, parameters, etc.
Source: latest.zip -> /example/03-load

1. Create new page!

     Use template 03-load/templets.php File, the user can change it to the new file name (example: newpage.php).

$lp = new lp();

$lp->masterCatalogue = 'languages/{newpage}';
$lp->userThemes      = '{newpage}';


See latest.zip -> /example/03-load/template.php

     Create the theme skin

Enter 03-load/themes And create {newpage}.php

     Create matchable language templates. E.g:


$lpvar = array (
	'lang_available'   => 'Available Languages:',


$lpvar = array (
	'lang_available'   => '可用语言:',

See latest.zip -> /example/03-load/languages/ en-us.php & zh-cn.php files in the directory.

     Directory Structure


2. Html is mixed with PHP language, for example:

<?php echo $lpvar['lang_available']; ?>

Example 4: Save Settings & Configuration

This example is different from dynamically reading and writing cookies; save the configuration to xml or cfg, read to select the available preferred language pack, and do not accept the browser's default language for preference.
Source: latest.zip -> /example/04-settings

1. Create a usable global parameter. E.g:

<?xml version="1.0" encoding="UTF-8" ?>

See latest.zip -> /example/04-settings/lp.xml file.


See latest.zip -> /example/04-settings/lp.cfg file.

2. Create new page!

     Use template 04-settings/templets.php File, the user can change it to the new file name (example: newpage.php).

$lp = new lp();

$lp->masterCatalogue = "themes/{newpage}";


     Create directories and matching languages

Enter 04-settings/themes/newpage, The created directory must match the {newpage} variable name.

     Directory Structure


Example 5: Database & Array

Connects to SQL database through PDO, and supports MySQL and SQLite. And use the Array function to list all available data.
Source: latest.zip -> /example/05-database

1. Create a database global configuration file.

     Use template latest.zip -> /example/05-database/lp-config.sample.php File, change to new file name: lp-config.php

2. Changing parameters is the same as your server configuration.

define('Database_Mode', '');

define('DB_HOST',       'localhost');

define('DB_NAME',       'lang-php');

define('DB_USER',       'username');

define('DB_PWD',        'password');

define('DB_PREFIX',     'lp_');

define('DB_CHARSET',    'utf8mb4');

3. Dynamic page connection code.


$page_team = 'homepage';

$current_lng = $db->select(DB_PREFIX."translate", "section = '$page_team'");
$lpna = $db->arraymodify($current_lng, $lng);

See latest.zip -> /example/05-database/index.php File.

     Array calling method.

<?php echo $lpna['lang_use_title1']['lp_variable']; ?>

      Use the print_r command to output all arrays.


4. Create new page!

Use template latest.zip -> /example/05-database/templets.php File, the user can change it to the new file name (example: newpage.php).

Modify the current page name for indexing.
$page_team = 'newpage';

Example 6: Standalone version & Portable

Use the array() language structure to build an array and complete all operations through functions; compared to other versions, the portable version is completed by a file.
Source: latest.zip -> /example/06-portable

1. The available language packs are set in advance and are done by query conditions.

$global_lp_all = array('en-us', 'zh-cn', 'zh-tw', 'ja-jp', 'ko-kr', 'ru-ru');

2. Create an array.

$lpna = array (
    'template' => array (
        'en-us' => 'template',
        'zh-cn' => '模板',
        'zh-tw' => '模板',
        'ja-jp' => '模板',
        'ko-kr' => '模板',
        'ru-ru' => '模板'),
    'end' => array (
        'en-us' => 'end',
        'zh-cn' => 'end',
        'zh-tw' => 'end',
        'ja-jp' => 'end',
        'ko-kr' => 'end',
        'ru-ru' => 'end')

3. Array calling method.

<?php echo $lpna['lang_page_title'][$lng]; ?>

Please pay attention to the writing of the array when using it, the array demo is only listed in part, please refer to the source code:latest.zip -> /example/06-portable/index.php

      Use the print_r command to output all arrays.


4. Resource conversion.

In the process of using the portable version, such as pictures, ICOs, you need to convert to base64 encoding. Javascript, CSS and other resources are completed with embedded code. Shortening tools can be used.

5. Online conversion website recommendation

Other supplements

Supplement refers to the hidden usage and other functions in use.

How to use the dynamic URL feature

Submit all requests to index.php for processing, including Nginx, Apache, IIS, etc.

  1. Nginx configuration example:

location / {
	try_files $uri $uri/ /index.php?$uri&$args;

  2. Apache, create .htaccess in the home directory of the website

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

  3. After opening index.php, enable the URL function.

$lp->isDynamic = true;

Use Javascript(JS) to switch languages and hide parameters

What is Javascript (JS) to switch languages and hide parameters? The purpose is to remove the suffix.
Before using mode 1: https://lang-php.com/?lang=zh-cn;
After using mode 2: https://lang-php.com,后缀没有了。

1. HTML template.

	<script src="assets/js/lp.js"></script>
	<a href="?lang=en-us">Switch</a>

Source: latest.zip -> /example/*/assets/js/lp.js

Jump to the specified domain name

What is the jump to the specified domain name? Some examples are by reading and matching the files in the directory. If you want to jump to the specified domain name, please refer to the following code:

Add code to the page you need to jump to!

/* sample 1

header("Location: http://us.lang-php.com");

/* sample 2

public $globalDomain = 'https://lang-php.com/';

function loading($lang)
	header("Location:" . $this->globalDomain . $lang);

/* sample 3

function loading($lang)
	switch ($lang) {
		case 'zh-cn': header("Location: https://cn.lang-php.com"); break;
		case 'zh-tw': header("Location: https://tw.lang-php.com"); break;
		case 'en-us': header("Location: https://us.lang-php.com"); break;
		case 'ru-ru': header("Location: https://ru.lang-php.com"); break;
		case 'ja-jp': header("Location: https://jp.lang-php.com"); break;
		case 'ko-kr': header("Location: https://kr.lang-php.com"); break;
		default: header("Location: https://global.lang-php.com"); break;