PHP code example of limoncello-php / l10n

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

    

limoncello-php / l10n example snippets


    $storage   = new BundleStorage($storageData);
    $localized = $storage->get('de_AT', 'ErrorMessages', 'id_or_message');

    // $localized
    ['Hallo Welt', 'de'];

    // $localized
    ['Hallo Welt aus Österreich', 'de_AT'];
 Resource/de/Messages.php

return [
    'Hello World' => 'Hallo Welt',
];
 Resource/de_AT/Messages.php

return [
    'Hello World' => 'Hallo Welt aus Österreich',
];

    $storageData = (new FileBundleEncoder('path/to/ResourcesFolder/'))->getStorageData('de');

    $storageData = (new FileBundleEncoder('path/to/ResourcesFolder/'))->getStorageData('de');
    $localized = (new BundleStorage($storageData))->get('de_AT', 'ErrorMessages', 'Hello World');
    // $localized
    ['Hallo Welt aus Österreich', 'de_AT'];

    $storageData = (new FileBundleEncoder('path/to/ResourcesFolder/'))->getStorageData('en');
    $translator = new Translator(new BundleStorage($storageData));

    // 'Hallo Welt' (message is in the resources)
    $translator->translateMessage('de', 'Messages', 'Hello World');

    // 'Hallo Welt aus Österreich' (message is in the resources)
    $translator->translateMessage('de_AT', 'Messages', 'Hello World');

    // 'Good morning' (message not found in resources so it returns the key itself)
    $translator->translateMessage('de', 'Messages', 'Good morning');

    $formatter = new Formatter('de', 'Messages', $translator);

    // 'Hallo Welt'
    $formatter->formatMessage('Hello World');

txt
Resources
    |_ de
        |_ Messages.php
    |_de_AT
        |_ Messages.php