PHP code example of popphp / pop-i18n

1. Go to this page and download the library: Download popphp/pop-i18n library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

popphp / pop-i18n example snippets


use Pop\I18n\I18n;

$lang = new I18n('fr_FR', '/path/to/language/files');

$string = $lang->__('Hello, my name is %1. I love to program %2.', ['Nick', 'PHP']);
echo $string;

$lang->_e('Hello, my name is %1. I love to program %2.', ['Nick', 'PHP']);

$lang = new I18n('fr_FR', '/path/to/language/files');

echo $lang->__('Hello, how are you?');                    // Bonjour, comment allez-vous?  (default)
echo $lang->__('Hello, how are you?', null, 'informal');  // Salut, ça va?

use Pop\I18n\Format;

$lang = [
    'src'    => 'en',
    'output' => 'de',
    'name'   => 'German',
    'native' => 'Deutsch'
];

$locales = [
    [
        'region' => 'DE',
        'name'   => 'Germany',
        'native' => 'Deutschland',
        'text' => [
            [
                'source' => 'This field is guage/files/de.xml');

// Create in JSON format
Format\Json::createFile($lang, $locales, '/path/to/language/files/de.json');

use Pop\I18n\Format;

// Create the XML format fragment
Format\Xml::createFragment('source/en.txt', 'output/de.txt', '/path/to/files/');

// Create the JSON format fragment
Format\Json::createFragment('source/en.txt', 'output/de.txt', '/path/to/files/');

use Pop\I18n\I18n;

$languages = I18n::getLanguages('/path/to/language/files');

use Pop\I18n\I18n;

$lang = new I18n('fr_FR');
$lang->loadFile('/path/to/language/files/fr.xml');
xml
<language src="en" output="fr" name="French" native="Français">
    <locale region="FR" name="France" native="France">
        <text>
            <source>Hello, how are you?</source>
            <output>
                <output>Bonjour, comment allez-vous?</output>
                <output alt="informal">Salut, ça va?</output>
            </output>
        </text>
    </locale>
</language>