PHP code example of nabeghe / light-localization

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

    

nabeghe / light-localization example snippets


use Nabeghe\LightLocalization\Localizer;

$en = new Localizer(__DIR__ . '/langs', 'en');
$fa = new Localizer(__DIR__ . '/langs', 'fa', $en); // $en is the fallback

// Reads from main.php (default group)
echo $fa->get('title');

// Reads from messages.php
echo $fa->get('success', 'messages');

// Returns a random item when the value is an array
echo $fa->rnd('greet');

new Localizer(
    string $path,
    string $locale = 'en',
    Localizer|string|null $fallback = null,
    ?string $defaultTranslationText = null,
    ?Atlin $atlin = null
);


// langs/en/main.php
return [
    'title'   => 'Hello World',
    'greet'   => ['Hi!', 'Hey!', 'Hello!'],
];

/langs/
  /en/
      main.php
      messages.php
      extra.atlin
  /fa/
      main.php
      extra.atlin