PHP code example of azwhosting / php_translate

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

    

azwhosting / php_translate example snippets


      use PhpTranslate\Translate;

    $translator = new Translate();
    

     return [
         'welcome' => 'Welcome',
         'goodbye' => 'Goodbye',
         // Ajoutez plus de traductions ici
     ];
     

     return [
         'welcome' => 'Bienvenue',
         'goodbye' => 'Au revoir',
         // Ajoutez plus de traductions ici
     ];
     

    echo Translate::__('welcome');
    echo Translate::__('goodbye');
    

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Example</title>
    </head>
    <body>
        <form method="post" action="">
            <label for="language">Choose language:</label>
            <select name="language" id="language" onchange="this.form.submit()">
                <option value="en" <?= $translator->getLanguage() == 'en' ? 'selected' : '' 

  return [
      'welcome' => 'Welcome',
      'goodbye' => 'Goodbye',
      'hello_world' => 'Hello World',
      // Ajoutez plus de traductions ici
  ];
  

  return [
      'welcome' => 'Bienvenue',
      'goodbye' => 'Au revoir',
      'hello_world' => 'Bonjour le monde',
      // Ajoutez plus de traductions ici
  ];
  
bash
composer 

php_translate
├── languages
│   ├── en_lang.php
│   └── fr_lang.php
├── src
│   ├── SessionManager.php
│   └── Translate.php
├── tests
│   └── TranslateTest.php
├── vendor
│   └── autoload.php
├── index.php
├── composer.json
└── README.md
bash
./vendor/bin/phpunit --bootstrap vendor/autoload.php tests