An open API service indexing awesome lists of open source software.

https://github.com/thejano/text-translator

This package allows to translate text using Google Translator for free without api.
https://github.com/thejano/text-translator

api google php translation translator

Last synced: 5 months ago
JSON representation

This package allows to translate text using Google Translator for free without api.

Awesome Lists containing this project

README

          

# Text Translator for PHP

[![Latest Version on Packagist](https://img.shields.io/packagist/v/thejano/text-translator.svg?style=flat-square)](https://packagist.org/packages/thejano/text-translator)
[![Total Downloads](https://img.shields.io/packagist/dt/thejano/text-translator.svg?style=flat-square)](https://packagist.org/packages/thejano/text-translator)

This package allows text translation using Google Translate for free without an API. It extracts the translated text from the Google Translate website. Meanwhile, it only supports Google Translate.

Supported Languages for Google Translate

https://cloud.google.com/translate/docs/languages

## Requirement

The package requires:
- PHP 8.0 or higher

## Installation

You can install the package via composer:

```bash
composer require thejano/text-translator
```

## Usage
You can use the package like below example
```php
translate($text,'ckb'); // ckb stands for Kurdish Sorani language

echo $translated; // Prints سڵاو جیهان

# Or Call statically
GoogleTranslator::translate($text,'ckb');

# Translate from Arabic to English
GoogleTranslator::translate('مرحبا بالعالم','en','ar'); // will returns Hello World

```

The class `GoogleTranslator` by default the source language is set to Auto, also you can override and provide target language on initiation.
```php
new GoogleTranslator(string $sourceLanguage = 'auto', string $targetLanguage = '')
```

The `translate` method can be called statically or non statically, and it accepts three parameters, which are:
```php
public function _translate(string $text, string $targetLanguage = '', string $sourceLanguage = ''): string;
```

## Testing

```bash
composer test
```
## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

## Credits

- [Dr Pshtiwan](https://github.com/drpshtiwan)
- [All Contributors](../../contributors)

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.