PHP code example of carica / localize

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

    

carica / localize example snippets


use Carica\Localize\Localize;

echo Localize::message('Example', meaning: 'test'), "\n";
echo Localize::message('Example', id: 'test.id'), "\n";
echo Localize::message('Example: {foo}', values: ['foo'=>'VALUE']), "\n";

use Carica\Localize\XSL\Callbacks;

$processor = new \XSLTProcessor();
$processor->registerPHPFunctions([Callbacks::XSL_CALLBACK]);

use Carica\Localize\Extraction;
use Carica\Localize\Serializer\Report\ConsoleReport;

$sourceLanguage = 'en';
$targetLanguages = ['de', 'fr'];

$messages = new Extraction(
  __DIR__.'../src/',
  [
    '(\\.php$)i' => new Extraction\PHPStaticFunctionExtractor()
    '(\\.xsl$)i' => new Extraction\XSLExtractor()
  ],
  function (Extraction\ConflictException $e) {
    echo $e->getMessage(), "\n";
  }
);
$messages->output(
  __DIR__.'../src/l10n',
  $sourceLanguage,
  $targetLanguages,
  'example',
  report: new ConsoleReport()
);

use Carica\Localize\Localize;
use Carica\Localize\Messages\XliffFileMessages;

Localize::messages(
  new XliffFileMessages(__DIR__.'/example.de.xlf')
);