PHP code example of lkt / translations

1. Go to this page and download the library: Download lkt/translations 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/ */

    

lkt / translations example snippets




return [
    'name' => 'Name',
    'billing' => [
        'address' => 'Billing address',
        'city' => 'Billing city',
    ]
];

use Lkt\Translations\Translations;

Translations::addLocalePath('en', __DIR__ . '/translations/en');
Translations::addLocalePath('es', __DIR__ . '/translations/es');
Translations::addLocalePath('it', __DIR__ . '/translations/it');
Translations::addLocalePath('fr', __DIR__ . '/translations/fr');

use Lkt\Translations\Translations;

$languages = Translations::getAvailableLanguages(); // An array => ['en', 'es', 'it', 'fr]

use Lkt\Translations\Translations;

// Get translations with current language
Translations::get('name');

// Nested translations can be accessed using the dot separator:
Translations::get('billing.address');

// Specify wanted language
Translations::get('name', 'it');

use Lkt\Translations\Translations;

Translations::setLang('es');

use Lkt\Translations\Translations;

$missed = Translations::getMissedTranslations()

[
    'en' => [
        'sayHello' => ''
    ],
    'es' => [
        'sayHello' => 'Hi'
    ]
]

use Lkt\Translations\Translations;

$missed = Translations::getTranslationsNotTranslated()

[
    'en' => [
        'lorem' => 'ipsum',
        'dolor.sit.amet' => 'Amet'
    ],
    'es' => [
        'lorem' => 'ipsum',
        'dolor.sit.amet' => 'Amet'
    ]
]

use Lkt\Translations\Translations;

$exported = Translations::export();

// $exported content:
[
    "en" => [
        "lorem" => "ipsum",
        "dolor.sit.amet" => "Dolor sit amet",
    ],
    "fr" => [
        "lorem" => "ipsum",
        "dolor.sit.amet" => "Dolor sit amet fr",
        "langExclusiveTranslation" => "Hi"
    ]
];
shell
- /
- - /translations
- - - /en
- - - - users.php
- - - - ...
- - - /es
- - - - users.php
- - - - ...
- - - /it
- - - - users.php
- - - - ...