Giter Site home page Giter Site logo

deepl's Introduction

Deepl in PHP

Translate texts. Simply.

A simple library without dependencies for automatic translation of your texts.

๐Ÿ“ฆ Installation

It's best to use Composer for installation, and you can also find the package on Packagist and GitHub.

To install, simply use the command:

$ composer require baraja-core/deepl

You can use the package manually by creating an instance of the internal classes, or register a DIC extension to link the services directly to the Nette Framework.

How to use

The library requires no dependencies. Simply create an instance, pass the API key and start translating:

$apiKey = '...';
$isFreeApiKey = true;
$deepl = new \Baraja\Deepl\Deepl($apiKey, $isFreeApiKey);

// Translate "Hello!" to DE
echo $deepl->translate('Hello!', DeeplLocale::DE);

The library is designed for maximum ease of use. At the same time, you can easily configure all the modules.

Supported languages

You can always get the list of supported languages from the DeeplLocale enum:

echo 'Supported languages: ';
$enumValues = array_map(static fn(\UnitEnum $case): string => htmlspecialchars($case->value ?? $case->name), DeeplLocale::cases());
echo implode(', ', $enumValues);

For normal translation work, we recommend using the built-in enum cases directly:

$deepl->translate('Text', DeeplLocale::CS, DeeplLocale::EN);

The first language parameter specifies the target language of the translation, the second parameter specifies the source language. If you don't specify a language, it will be detected automatically.

Translation cache

We know that translating the same requests over and over again can be very expensive for you, because the API is charged by real requests. Therefore, the library directly implements a native cache that stores translation results in a temporary storage.

The default cache implementation is the FileResultCache service, in which you can configure a custom disk path. The default storage for the cache is sys_get_temp_dir() . '/deepl'.

$cache = new \Depl\FileResultCache(__DIR__ . '/cache');
$apiKey = '...';
$deepl = new \Baraja\Deepl\Deepl($apiKey, false, $cache);

๐Ÿ“„ License

baraja-core/deepl is licensed under the MIT license. See the LICENSE file for more details.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.