Download the PHP package vildanbina/laravel-auto-translation without Composer

On this page you can find all versions of the php package vildanbina/laravel-auto-translation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-auto-translation

Laravel Auto Translation

Latest Stable Version Total Downloads License PHP Version Require

Introduction

Laravel Auto Translation is a robust package designed to simplify and streamline the localization of your Laravel application. By automating the translation of your language files, this package ensures a more efficient workflow. Key features include:

  1. Multiple Drivers: ChatGPT, Google Translate, and DeepL.
  2. JSON & PHP Language File Support: Scans both JSON and nested PHP files.
  3. Placeholder Preservation: Automatically protects placeholders like :attribute or :seconds from being altered.

Requirements

Installation

Install the package using Composer:

composer require vildanbina/laravel-auto-translation

Publish the configuration file:

php artisan vendor:publish --provider="VildanBina\LaravelAutoTranslation\AutoTranslationsServiceProvider"

Configuration

The configuration file is located at config/auto-translations.php. Below is an example of its default settings. Customize these settings to suit your application, such as specifying the default driver or changing the source language:

<?php

return [
    'lang_path' => lang_path(),

    'default_driver' => env('TRANSLATION_DEFAULT_DRIVER', 'chatgpt'),

    'source_language' => env('TRANSLATION_SOURCE_LANGUAGE', 'en'),

    'drivers' => [
        'chatgpt' => [
            'api_key'     => env('CHATGPT_API_KEY'),
            'model'       => env('CHATGPT_MODEL', 'gpt-3.5-turbo'),
            'temperature' => env('CHATGPT_TEMPERATURE', 0.7),
            'max_tokens'  => env('CHATGPT_MAX_TOKENS', 1000),
            'http_timeout' => env('CHATGPT_HTTP_TIMEOUT', 30),
        ],
        'google' => [
            'api_key' => env('GOOGLE_API_KEY'),
        ],
        'deepl' => [
            'api_key' => env('DEEPL_API_KEY'),
            'api_url' => env('DEEPL_API_URL', 'https://api-free.deepl.com/v2/translate'),
        ],

        // Example of a custom driver registration:
        // 'my_custom_driver' => [
        //     'class'   => \App\Drivers\MyCustomDriver::class,
        //     'api_key' => env('MY_CUSTOM_API_KEY'),
        // ],
    ],
];

Setting Up Environment Variables

Add the required API keys to your .env file. Obtain these keys from the respective service providers:

TRANSLATION_DEFAULT_DRIVER=chatgpt
TRANSLATION_SOURCE_LANGUAGE=en
CHATGPT_API_KEY=your-chatgpt-api-key
GOOGLE_API_KEY=your-google-api-key
DEEPL_API_KEY=your-deepl-api-key

Commands

1. translate:scan

This command scans all PHP files located within the lang/ folder (including nested directories), extracting translatable strings and saving them in a JSON file (lang/texts_to_translate.json). This file serves as the base for subsequent translations.

Usage:

php artisan translate:scan --lang=en

2. translate:default

This command translates the strings defined in texts_to_translate.json into a specified target language using the chosen translation driver. It also preserves Laravel placeholders from being translated.

Usage:

php artisan translate:default fr --driver=deepl --overwrite

3. Using In-Memory Texts (If Applicable)

In addition to scanning and translating language files, you can programmatically set texts directly in memory. This is useful for scenarios where you want to translate specific texts without relying on language files.

Example:

use VildanBina\LaravelAutoTranslation\TranslationWorkflowService;
use VildanBina\LaravelAutoTranslation\Services\TranslationEngineService;

// Assume $translationEngineService is an instance of TranslationEngineService
$translationWorkflowService = new TranslationWorkflowService($translationEngineService);

// Define texts to translate
$texts = [
    'welcome.message' => 'Welcome to our application!',
    'user.greeting' => 'Hello, :name!',
];

// Set texts in memory
$translationWorkflowService->setInMemoryTexts($texts);

// Perform translation
$translatedTexts = $translationWorkflowService->translate('en', 'fr', 'deepl');

// Output translated texts
print_r($translatedTexts);

Custom Drivers

To add a custom driver, follow these steps:

  1. Implement the TranslationDriver interface:

    use VildanBina\LaravelAutoTranslation\Contracts\TranslationDriver;
    
    class MyCustomDriver implements TranslationDriver
    {
       public function __construct(private array $config)
       {
       }
    
       public function translate(array $texts, string $sourceLang, string $targetLang): array
       {
           // Your custom logic...
           return $texts;
       }
    }
  2. Register the driver in auto-translations.php:

    'drivers' => [
       'my_custom_driver' => [
           'class'   => \App\Drivers\MyCustomDriver::class,
           'api_key' => env('MY_CUSTOM_API_KEY'),
           // additional config...
       ],
    ],
  3. Use it in translations:
    php artisan translate:default fr --driver=my_custom_driver

Supported Drivers

Contributing

See CONTRIBUTING for details.

Security Vulnerabilities

Please e-mail [email protected] to report any security vulnerabilities instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-auto-translation with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
mehrab-wj/tiktoken-php Version ^1.0
laravel/framework Version ^9.0|^10.0|^11.0
illuminate/support Version ^9.0|^10.0|^11.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package vildanbina/laravel-auto-translation contains the following files

Loading the files please wait ....