Quick Guide
This quick guide will show you how to use and create it to master and master the tutorial.
This quick guide will show you how to use and create it to master and master the tutorial.
Includes: Provides different ones for you to choose and use.
Steering after first run 'choose-country-region'Directory, select the language directory to match, with memory function.
Source: latest.zip -> /example/01-directory
Automatically search for files in the matching directory. If no file is found, the default file is selected.
Source: latest.zip -> /example/02-embed
en-us.php
Embedded en-us.php files;
zh-cn.php
Embed zh-cn.php file;
See the files in the latest.zip->/example/02-embed/themes/homepage directory.
$lp = new lp();
$lp->masterCatalogue = "themes/{newpage}";
$lp->run();
Enter 02-embed/themes/newpage, the created directory must be consistent with the {newpage} variable name.
02-embed/newpage.php
02-embed/themes/newpage
Automatically search for matching language files and load them after loading, including: string characters, parameters, etc.
Source: latest.zip -> /example/03-load
$lp = new lp();
$lp->masterCatalogue = 'languages/{newpage}';
$lp->userThemes = '{newpage}';
$lp->run();
See latest.zip -> /example/03-load/template.php
Enter 03-load/themes And create {newpage}.php
en-us.php
$lpvar = array (
'lang_available' => 'Available Languages:',
);
zh-cn.php
$lpvar = array (
'lang_available' => '可用语言:',
);
See latest.zip -> /example/03-load/languages/ en-us.php & zh-cn.php files in the directory.
03-load/{newpage}.php
03-load/languages/{newpage}
03-load/themes/{newpage}
<?php echo $lpvar['lang_available']; ?>
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
XML
<?xml version="1.0" encoding="UTF-8" ?>
<setting>
<languages>
en-us
</languages>
</setting>
See latest.zip -> /example/04-settings/lp.xml file.
lp.cfg
Global_DFLT_Lang=en-us
See latest.zip -> /example/04-settings/lp.cfg file.
$lp = new lp();
$lp->masterCatalogue = "themes/{newpage}";
$lp->run();
Enter 04-settings/themes/newpage, The created directory must match the {newpage} variable name.
04-settings/newpage.php
04-settings/themes/newpage
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
Use template latest.zip -> /example/05-database/lp-config.sample.php File, change to new file name: lp-config.php
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');
include_once('lp-load.php');
$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.
<?php echo $lpna['lang_use_title1']['lp_variable']; ?>
print_r($current_page);
print_r($lpna);
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';
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
$global_lp_all = array('en-us', 'zh-cn', 'zh-tw', 'ja-jp', 'ko-kr', 'ru-ru');
$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')
);
<?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
print_r($lpna);
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.
Supplement refers to the hidden usage and other functions in use.
Submit all requests to index.php for processing, including Nginx, Apache, IIS, etc.
location / {
try_files $uri $uri/ /index.php?$uri&$args;
}
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
$lp->isDynamic = true;
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,后缀没有了。
<html>
<headl>
<script src="assets/js/lp.js"></script>
</headl>
<body>
<a href="?lang=en-us">Switch</a>
</body>
</html>
Source: latest.zip -> /example/*/assets/js/lp.js
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:
/* 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;
}
}