PHP code example of klehm / content-blocks-i18n

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

    

klehm / content-blocks-i18n example snippets


$builder->add('title', TextType::class, [
    'label' => 'Title',
    'cb_translatable' => true,
]);

#[Route('/{_locale}/page/{id}', Response
{
    // No mention of translation anywhere — the render pipeline resolves the
    // request locale and merges the stored values.
}

$html = $renderer->render($area, RenderContext::forPublic('de'));

use ContentBlocks\I18n\Machine\TranslationProviderInterface;

final class MyProvider implements TranslationProviderInterface
{
    public static function getName(): string { return 'mine'; }
    public function getLabel(): string { return 'My engine'; }
    public function supports(string $source, string $target): bool { return true; }

    /** @param list<TranslationRequest> $requests @return list<TranslationOutcome> */
    public function translate(array $requests, TranslationJob $job): array
    {
        // one call, many strings
    }
}