PHP code example of vertilia / text

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

    

vertilia / text example snippets




new Vertilia\Text\Text();

echo $t->_('Just a test'), PHP_EOL;                      // output: Just a test
echo $t->pget('page', 'Next'), PHP_EOL;                  // output: Next
echo $t->nget('One page', 'Multiple pages', 1), PHP_EOL; // output: One page
echo $t->nget('One page', 'Multiple pages', 5), PHP_EOL; // output: Multiple pages
echo $t->npget('page', 'One sent', 'Multiple sent', 5), PHP_EOL; // output: Multiple sent



new App\L10n\MessagesFr();

echo $t->_('Just a test'), PHP_EOL;                      // output: Juste un test
echo $t->pget('page', 'Next'), PHP_EOL;                  // output: Suivante
echo $t->nget('One page', 'Multiple pages', 1), PHP_EOL; // output: Une page
echo $t->nget('One page', 'Multiple pages', 5), PHP_EOL; // output: Plusieurs pages
echo $t->npget('page', 'One sent', 'Multiple sent', 5), PHP_EOL; // output: Plusieurs envoyées

public function _(string $message): string;

$t = \Vertilia\Text\Text();
echo $t->_("Several words"); // output: Several words

$t = \App\L10n\MessagesRu();
echo $t->_("Several words"); // output: Несколько слов

public function nget(string $singular, string $plural, int $count): string;

$t = \Vertilia\Text\Text();
printf($t->nget("%u word", "%u words", 1), 1); // output: 1 word
printf($t->nget("%u word", "%u words", 2), 2); // output: 2 words
printf($t->nget("%u word", "%u words", 5), 5); // output: 5 words

$t = \App\L10n\MessagesRu();
printf($t->nget("%u word", "%u words", 1), 1); // output: 1 слово
printf($t->nget("%u word", "%u words", 2), 2); // output: 2 слова
printf($t->nget("%u word", "%u words", 5), 5); // output: 5 слов

public function npget(string $context, string $singular, string $plural, int $count): string;

$t = \Vertilia\Text\Text();
printf($t->npget("star", "%u bright", "%u bright", 1), 1); // output: 1 bright
printf($t->npget("star", "%u bright", "%u bright", 2), 2); // output: 2 bright
printf($t->npget("star", "%u bright", "%u bright", 5), 5); // output: 5 bright

$t = \App\L10n\MessagesRu();
printf($t->npget("star", "%u bright", "%u bright", 1), 1); // output: 1 яркая
printf($t->npget("star", "%u bright", "%u bright", 2), 2); // output: 2 яркие
printf($t->npget("star", "%u bright", "%u bright", 5), 5); // output: 5 ярких

public function pget(string $context, string $message): string;

$t = \Vertilia\Text\Text();
printf($t->npget("star", "It's bright")); // output: It's bright

$t = \App\L10n\MessagesRu();
printf($t->npget("star", "It's bright")); // output: Она яркая

printf($t->nget("%d file removed", "%d files removed", $n), $n);

  putenv('LC_ALL=fr_FR');
  setlocale(LC_ALL, 'fr_FR');
  bindtextdomain("myPHPApp", "./locale");
  textdomain("myPHPApp");
  echo gettext("Welcome to My PHP Application"), "\n";
  echo dgettext("anotherPHPApp", "Welcome to Another PHP Application"), "\n";
  

  $myDomain = \App\L10n\MyPhpAppFr();
  $anotherDomain = \App\L10n\AnotherPhpAppFr();
  echo $myDomain->_("Welcome to My PHP Application"), "\n";
  echo $anotherDomain->_("Welcome to Another PHP Application"), "\n";
  

/app/
├─ locale/
│  ├─ en_US/
│  │  └─ LC_MESSAGES/
│  │     └─ messages.po
│  ├─ fr_FR/
│  │  └─ LC_MESSAGES/
│  │     └─ messages.po
│  ├─ ru_RU/
│  │  └─ LC_MESSAGES/
│  │     └─ messages.po
│  └─ messages.pot
├─ src/
│  ├─ L10n/
│  │  ├─ MessagesEn.php
│  │  ├─ MessagesFr.php
│  │  └─ MessagesRu.php
│  └─ ...
├─ vendor/
│  ├─ autoload.php
│  ├─ composer/
│  └─ vertilia/
├─ www/
│  └─ index.php
├─ .gitattributes
└─ composer.json
shell
docker run --rm --volume "$PWD":/app php \
  /app/vendor/bin/po2php -n App\\Tests\\Locale -c MessagesRu \
  /app/tests/locale/ru_RU/LC_MESSAGES/messages.po \
  >tests/locale/MessagesRu.php