PHP code example of yiisoft / i18n-message-gettext

1. Go to this page and download the library: Download yiisoft/i18n-message-gettext 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/ */

    

yiisoft / i18n-message-gettext example snippets


use Yiisoft\Translator\CategorySource;
use Yiisoft\Translator\Message\Gettext\MessageSource;

$categorySource = new CategorySource(
    'my-category',
    new MessageSource('/path/to/messages'),
);

/** @var string $path - path to your gettext storage */
$messageSource = new \Yiisoft\Translator\Message\Gettext\MessageSource($path);

/** 
 * @var \Yiisoft\Translator\Message\Gettext\MessageSource $messageSource
 * @var ?string $translatedString
 */
$id = 'messageIdentificator';
$category = 'messages';
$language = 'de-DE';

$translatedString = $messageSource->getMessage($id, $category, $language);