2017 © Pedro Peláez
 

library translation

RW Translation Service

image

rw/translation

RW Translation Service

  • Tuesday, April 17, 2018
  • by swang
  • Repository
  • 5 Watchers
  • 1 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 64 Versions
  • 0 % Grown

The README.md

Build Status Coverage Status Latest Stable Version, (*1)

Install

composer require revenuewire/translation, (*2)

Description

Translation Services using DyanmoDB or Redis as cache options. We also embedded two translation service providers, One Hour Translation and Google Cloud Translation., (*3)

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., (*4)

Requirements

Generally, there are two modes (live or db) of configurations you can choose from., (*5)

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., (*6)

Requirement Summary
  • Google Cloud Account
  • Redis
DB Mode

Database mode uses AWS DynamoDB as a storage choice. Redis is suggested but not required., (*7)

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., (*8)

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., (*9)

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., (*10)

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., (*11)

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., (*12)

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., (*13)

Code Google Cloud Translation One Hour Translation Language Display Note
en en en-us English English
af af af Afrikaans Afrikaans
ar ar ar-sa Arabic العربية
bg bg bg-bg Bulgarian Български
zh zh zh-cn-cmn-s Chinese (Simple) 简体中文
zh-cn zh-cn zh-cn-cmn-s Chinese (Simple) 简体中文 BCP-47
zh-tw zh-tw zh-cn-cmn-t Chinese (Traditional) 繁體中文 BCP-47
hr hr hr-hr Croatian hrvatski
cs cs cs-cz Czech český
da da da-dk Danish dansk
nl nl nl-nl Dutch Nederlands
fr fr fr-fr French français
de de de-de German Deutsch
el el el-gr Greek ελληνικά
iw iw N/A Hebrew עברית
hi hi hi-in Hindi हिन्दी
is is is-is Icelandic íslenska
id id id-id Indonesian Bahasa Indonesia
it it it-it Italian italiano
ja ja jp-jp Japanese 日本語
ko ko ko-kp Korean 한국어
no no no-no Norwegian Norsk
pl pl pl-pl Polish polski
pt pt pt-pt Portuguese português
pt-br N/A pt-br Portuguese (Brazil) português - Brasil ISO 639.2
pt-pt pt pt-pt Portuguese (Portugal) português ISO 639.2
ro ro ro-ro Romanian limba română
ru ru ru-ru Russian Русский
sk sk sk-sk Slovak slovenčina
es es es-es Spanish español
sv sv sv-se Swedish svenska
th th th-th Thai ภาษาไทย
tr tr tr-tr Turkish Türkçe
vi vi vi-vn Vietnamese Tiếng Việt
fi N/A fi-fi Finnish suomi

The Versions

17/04 2018
19/02 2018
01/09 2017
01/09 2017

dev-feature/remove-slug

dev-feature/remove-slug https://github.com/cosmostail/translation

RW Translation Service

  Sources   Download

Apache License 2.0

The Requires

 

The Development Requires

by Scott Wang

19/08 2017
19/08 2017

dev-feature/namespace-test

dev-feature/namespace-test https://github.com/cosmostail/translation

RW Translation Service

  Sources   Download

Apache License 2.0

The Requires

 

The Development Requires

by Scott Wang

18/08 2017
18/08 2017
17/08 2017
17/08 2017
17/08 2017
17/08 2017
16/08 2017
16/08 2017
16/08 2017

dev-feature/bug-fix-1

dev-feature/bug-fix-1 https://github.com/cosmostail/translation

RW Translation Service

  Sources   Download

Apache License 2.0

The Requires

 

by Scott Wang

11/08 2017
04/08 2017
04/08 2017
25/07 2017
23/06 2017
23/06 2017
16/06 2017
16/06 2017
16/06 2017
15/06 2017
15/06 2017
15/06 2017
13/06 2017
03/06 2017
02/06 2017
01/06 2017
31/05 2017
31/05 2017
31/05 2017
25/05 2017
25/05 2017
25/05 2017
10/05 2017
09/05 2017
09/05 2017
09/05 2017
05/05 2017
05/05 2017
28/04 2017

v1.4

1.4.0.0 https://github.com/cosmostail/translation

RW Translation Service

  Sources   Download

Apache License 2.0

The Requires

 

by Scott Wang

28/04 2017

v1.3

1.3.0.0 https://github.com/cosmostail/translation

RW Translation Service

  Sources   Download

Apache License 2.0

The Requires

 

by Scott Wang

27/04 2017

v1.2

1.2.0.0 https://github.com/cosmostail/translation

RW Translation Service

  Sources   Download

Apache License 2.0

The Requires

 

by Scott Wang

27/04 2017

v1.21

1.21.0.0 https://github.com/cosmostail/translation

RW Translation Service

  Sources   Download

Apache License 2.0

The Requires

 

by Scott Wang

27/04 2017

v1.1

1.1.0.0 https://github.com/cosmostail/translation

RW Translation Service

  Sources   Download

Apache License 2.0

The Requires

 

by Scott Wang

27/04 2017

1.1

1.1.0.0 https://github.com/cosmostail/translation

RW Translation Service

  Sources   Download

Apache License 2.0

The Requires

 

by Scott Wang

08/04 2017

v1.0

1.0.0.0 https://github.com/cosmostail/translation

RW Translation Service

  Sources   Download

Apache License 2.0

The Requires

 

by Scott Wang