Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joeybab3/phphtmltranslator
PHP HTML Translator.
https://github.com/joeybab3/phphtmltranslator
Last synced: 21 days ago
JSON representation
PHP HTML Translator.
- Host: GitHub
- URL: https://github.com/joeybab3/phphtmltranslator
- Owner: joeybab3
- Created: 2023-10-23T22:39:42.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-25T22:48:15.000Z (27 days ago)
- Last Synced: 2024-11-25T23:30:29.322Z (27 days ago)
- Language: PHP
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# phphtmltranslator
PHP HTML TranslatorTranslates HTML into a destination language using Stichoza's Google Translate PHP:
https://github.com/Stichoza/google-translate-phpIt 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.
```