PHP code example of khalyomede / laravel-translate

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

    

khalyomede / laravel-translate example snippets


return [
  "langs" => [
    "fr",
    "en",
    "pt",
  ],
  // ...
];

return [
  "langs" => [
    "fr",
    "en",
    "pt",
  ],
  // ...
];

return [
  // ...
  "urces/views",
  ],
  // ...
];

return [
  "remove_missing_keys" => true,
  // ...
];

use App\Models\UserType;

return [
  // ...
  "models" => [
    UserType::class => "name",
  ],
  // ...
];

use App\Models\Post;

return [
  // ...
  "models" => [
    Post::class => [
      "title",
      "description",
    ],
  ],
  // ...
];

use App\Constants\InvoiceStatus;

return [
  // ...
  "translatables" => [
    fn () => [ InvoiceStatus::PENDING, InvoiceStatus::SENT, InvoiceStatus::PAID ],
  ]
];

use App\Constants\InvoiceStatus;

return [
  // ...
  "translatables" => [
    fn () => collect([InvoiceStatus::PENDING, InvoiceStatus::SENT, InvoiceStatus::PAID]),
  ]
];

use App\Constants\InvoiceStatus;
use App\Enums\UserRole;

return [
  // ...
  "translatables" => [
    fn () => collect(InvoiceStatus::PENDING, InvoiceStatus::SENT, InvoiceStatus::PAID]),
    fn () => collect(UserRole::cases())->map(fn (UserRole $userRole): string => $userRole->toString()),
  ]
];

return [
  // ...
  "ignore_keys" => [
    "Welcome",
  ]
  // ...
];
bash
php artisan vendor:publish --tag "translate"
bash
php artisan translate