revenuewire / translation
RW Translation Service
Installs: 2 413
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 8
Forks: 2
Open Issues: 0
Requires
- google/cloud: ^0.257
- onehourtranslation/api2: ^1.0
- symfony/yaml: ^4.4.45
Requires (Dev)
- phpunit/phpunit: ^9
- dev-master
- 5.0.0
- 4.0.2
- v4.0.1
- v4.0.0
- v3.1.4.x-dev
- v3.1.4
- v3.1.3
- v3.1.2
- v3.1.1
- v3.1.0
- v3.0.7
- v3.0.6
- v3.0.5
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v2.x-dev
- 2.0.3
- v2.0.2.x-dev
- v2.0.2
- v2.0.1
- v2.0.0
- v1.92
- v1.91
- v1.90
- v1.89.5
- v1.89.4
- v1.89.3
- v1.89.2
- v1.89.1
- v1.89
- v1.88
- v1.87
- v1.86
- v1.85
- v1.84
- v1.83
- v1.82
- v1.81
- v1.80
- v1.79
- v1.78
- v1.77
- v1.76
- v1.75
- v1.74
- v1.73
- v1.72
- v1.71
- v1.70
- v1.69
- v1.68
- v1.67
- v1.66
- v1.65
- v1.64
- v1.63
- v1.62
- v1.61
- v1.60
- v1.21
- v1.5
- v1.4
- v1.3
- v1.2
- v1.1
- v1.0
- dev-develop
- dev-add-fi-to-nmt
This package is auto-updated.
Last update: 2024-11-06 02:38:36 UTC
README
Install
composer require revenuewire/translation
Description
Translation Services using DyanmoDB or Redis as cache options. We also embedded two translation service providers, One Hour Translation and Google Cloud Translation.
OneHourTranslation provides human translators to translate your project where Google Cloud Translation charges a flat fee for Neural Machine Translation (NMT). Both service providers provide simple machine translation but are not supported for the purpose of this project.
Requirements
Generally, there are two modes (live or db) of configurations you can choose from.
Live Mode
Live mode uses Google Cloud Translation APIs that translate the texts directly to targeted languages. You need a Google Cloud account and key in order to use it. You also need Redis cache for better performance. No memcached support yet.
Requirement Summary
- Google Cloud Account
- Redis
DB Mode
Database mode uses AWS DynamoDB as a storage choice. Redis is suggested but not required.
Requirement Summary
- AWS DynamoDB
- Redis (optional)
Configurations
Live Mode
$defaultLanguage = "en"; $supportLanguages = ["en", "fr", "zh"]; $redisConfig = [ "host" => "REDIS_HOST", "timeout" => "0.5", "port" => "6379", "prefix" => "t_2sx_", //optional, to prevent cache key collision ]; $gct = [ "project" => "GOOGLE_CLOUD_PROJECT_ID", "key" => "GOOGLE_CLOUD_PROJECT_KEY" ]; $translationService = new \RW\Translation(null, $supportLanguages, $cache, $defaultLanguage, $gct); //translate to Simple Chinese echo $translationService->translate("Hello World", "zh"); print_r($translationService->batchTranslate([ "hello" => "Hello World", "how-s-going" => "How's going?" ],"zh"));
DB Mode
Install
php vendor/revenuewire/translation/bin/cli.php \ --region=[AWS_REGION] \ --translation=[TRANSLATION_TABLE] \ --translation_queue=[TRANSLATION_QUEUE_TABLE] \ --translation_project=[TRANSLATION_PROJECT_TABLE] \ init
Usage
$defaultLanguage = "en"; $supportLanguages = ["en", "fr", "zh"]; $dynamoConfig = [ "region" => "us-west-2", "table" => "YOUR TABLE NAME", "version" => "2012-08-10" ]; $redisConfig = [ "host" => "YOUR REDIS HOST", "timeout" => "0.5", "port" => "6379", "prefix" => "t_2sx_", //optional, to prevent cache key collision ]; $translationService = new \RW\Translation($dynamoConfig, $supportLanguages, $cache, $defaultLanguage); //translate to Simple Chinese echo $translationService->translate("Hello World", "zh"); print_r($translationService->batchTranslate([ "hello" => "Hello World", "how-s-going" => "How's going?" ],"zh"));
Working with Translation Services
Once you go through all your pages, your translation table should have collected all texts you need to translate.
diff
Calculate the difference between existing texts and targeted translation texts. For example, if your source table have a English word "Hello World", and the following command will generate two queue items that aim to translate "Hello World" to Chinese and French.
php vendor/revenuewire/translation/bin/cli.php \ --provider=[OTH or GCT] \ --region=[AWS_REGION] \ --translation=[TRANSLATION_TABLE] \ --translation_queue=[TRANSLATION_QUEUE_TABLE] \ --translation_project=[TRANSLATION_PROJECT_TABLE] \ diff zh fr
add
The add command will add all pending items into projects. This is useful when working with OneHourTranslation which had limits on how many texts you can schedule to translate per batch.
php vendor/revenuewire/translation/bin/cli.php \ --region=[AWS_REGION] \ --translation=[TRANSLATION_TABLE] \ --translation_queue=[TRANSLATION_QUEUE_TABLE] \ --translation_project=[TRANSLATION_PROJECT_TABLE] \ --oth_pubkey=[ONE_HOUR_TRANSLATION_PUB_KEY] \ --oth_secret=[ONE_HOUR_TRANSLATION_SECRET] \ --oth_sandbox=[ONE_HOUR_TRANSLATION_SANDBOX] \ --gct_project=[GOOGLE_CLOUD_PROJECT] \ --gct_key=[GOOGLE_CLOUD_KEY] \ add
commit
Commit the projects to service provider. The commit only available for One Hour Translation.
php vendor/revenuewire/translation/bin/cli.php \ --region=[AWS_REGION] \ --translation=[TRANSLATION_TABLE] \ --translation_queue=[TRANSLATION_QUEUE_TABLE] \ --translation_project=[TRANSLATION_PROJECT_TABLE] \ --oth_pubkey=[ONE_HOUR_TRANSLATION_PUB_KEY] \ --oth_secret=[ONE_HOUR_TRANSLATION_SECRET] \ --oth_sandbox=[ONE_HOUR_TRANSLATION_SANDBOX] \ commit
push
Push the translated texts back to translation table.
php vendor/revenuewire/translation/bin/cli.php \ --region=[AWS_REGION] \ --translation=[TRANSLATION_TABLE] \ --translation_queue=[TRANSLATION_QUEUE_TABLE] \ --translation_project=[TRANSLATION_PROJECT_TABLE] \ push
Languages Support
Most language code parameters conform to ISO-639-1 identifiers, except where noted.