Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/joeybab3/phphtmltranslator

PHP HTML Translator.
https://github.com/joeybab3/phphtmltranslator

Last synced: 21 days ago
JSON representation

PHP HTML Translator.

Awesome Lists containing this project

README

        

# phphtmltranslator
PHP HTML Translator

Translates HTML into a destination language using Stichoza's Google Translate PHP:
https://github.com/Stichoza/google-translate-php

It has all the same limitations, namely that since it uses the free Google Translate API, you may run into rate limits or a temporary IP Ban.

It uses a SQL database to cache previously translated tokens so running html through it repeatedly with only minor changes will be much faster.

# Setup

`composer require joeybab3/phphtmltranslator`

Once installed run the following PHP somewhere:
```php
getMessage(), (int)$e->getCode());
}

Translator::createTranslationCacheTable($db);
```

This will create the cache table. Alternatively, create the table yourself:
```sql
CREATE TABLE `translations` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`text` text,
`result` text,
`lang` varchar(4) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
```

Then you can use it to translate HTML:
```php
This text is not bold but this text is boldThis text, on the other hand, will be a separate translation entirely.";

$result = $TR->tokenizedTranslate($html);

//


Este texto no está en negrita pero este texto está en negritaEste texto, por otro lado, será una traducción completamente separada.
```