All Projects → gzigzigzeo → google_translate_diff

gzigzigzeo / google_translate_diff

Licence: other
Google Translate API wrapper translates only changes between revisions of big texts

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to google translate diff

php-google-translate-for-free
Library for free use Google Translator. With attempts connecting on failure and array support.
Stars: ✭ 124 (+143.14%)
Mutual labels:  google-translate, google-translator
swarm-gcp-faas
Setup OpenFaaS on Google Cloud with Terraform, Docker Swarm and Weave
Stars: ✭ 15 (-70.59%)
Mutual labels:  google-cloud
stackdriver-to-discord
[Unmaintained] ⚙️ A simple Google Cloud Function in Go to transform / proxy Stackdriver Static Webhook notifications to Discord.
Stars: ✭ 18 (-64.71%)
Mutual labels:  google-cloud
monolog-google-cloud-json-formatter
A Monolog extension for formatting log entries for Google Cloud Logging
Stars: ✭ 15 (-70.59%)
Mutual labels:  google-cloud
bn.reactjs.org
(Work in progress) React documentation website in Bengali
Stars: ✭ 60 (+17.65%)
Mutual labels:  translation
website
Comunidade Brasileira Ember
Stars: ✭ 14 (-72.55%)
Mutual labels:  translation
activemodel-datastore
Ruby on Rails with Active Model and Google Cloud Datastore. Extracted from Agrimatics Aero.
Stars: ✭ 47 (-7.84%)
Mutual labels:  google-cloud
XTranslate
Easy translate text on web pages (chrome extension)
Stars: ✭ 64 (+25.49%)
Mutual labels:  translation
bigquery-to-datastore
Export a whole BigQuery table to Google Datastore with Apache Beam/Google Dataflow
Stars: ✭ 56 (+9.8%)
Mutual labels:  google-cloud
kube-secrets-init
Kubernetes mutating webhook for `secrets-init` injection
Stars: ✭ 106 (+107.84%)
Mutual labels:  google-cloud
Docs
VS Code docs の非公式日本語訳
Stars: ✭ 16 (-68.63%)
Mutual labels:  translation
netty-in-action-cn
Netty In Action 中文版
Stars: ✭ 1,389 (+2623.53%)
Mutual labels:  translation
legesher-translations
Home of all the translations for spoken languages into programming language
Stars: ✭ 47 (-7.84%)
Mutual labels:  translation
mobx-react-intl
A connector between mobx-react and react-intl
Stars: ✭ 32 (-37.25%)
Mutual labels:  translation
dataflow-contact-center-speech-analysis
Speech Analysis Framework, a collection of components and code from Google Cloud that you can use to transcribe audio files to create analytics.
Stars: ✭ 46 (-9.8%)
Mutual labels:  google-cloud
gtoken
Securely access AWS services from GKE cluster
Stars: ✭ 43 (-15.69%)
Mutual labels:  google-cloud
google-cloud-powershell
PowerShell cmdlets for the Google Cloud Platform
Stars: ✭ 120 (+135.29%)
Mutual labels:  google-cloud
bigquery-kafka-connect
☁️ nodejs kafka connect connector for Google BigQuery
Stars: ✭ 17 (-66.67%)
Mutual labels:  google-cloud
EverTranslator
Translate text anytime and everywhere, even you are gaming!
Stars: ✭ 59 (+15.69%)
Mutual labels:  translation
google-drive-direct-remote-upload
Directly upload files from the web to Google Drive without saving them completely on the server before.
Stars: ✭ 62 (+21.57%)
Mutual labels:  google-cloud

GoogleTranslateDiff

Google Translate API wrapper helps to translate only changes between revisions of long texts.

Sponsored by Evil Martians

Build Status Code Climate Test Coverage

Use case

Assume your project contains a significant amount of products descriptions which:

  • Require retranslation each time user edits them.
  • Have a lot of equal parts (like return policy).
  • Change frequently.

If your user changes a single word within the long description, you will be charged for the retranslation of the whole text.

Much better approach is to try to translate every repeated structural element (sentence) in your texts array just once to save money. This gem helps to make it done.

Installation

Add this line to your application's Gemfile:

gem 'google_translate_diff'

And then execute:

$ bundle

Or install it yourself as:

$ gem install google_translate_diff

Usage

require "google_translate_diff"

# This dependencies are not included, as you might need to roll your own cache based on different store
require "redis"
require "connection_pool"
require "redis-namespace"
require "ratelimit" # Optional, if you will use

# Setup https://github.com/GoogleCloudPlatform/google-cloud-ruby/tree/master/google-cloud-translate
ENV["TRANSLATE_KEY"] = "foobarkey"

# I always use pool for redis
pool = ConnectionPool.new(size: 10, timeout: 5) { Redis.new }

# Pass any options (like app id)
GoogleTranslateDiff.api = Google::Cloud::Translate.new

GoogleTranslateDiff.cache_store =
  GoogleTranslateDiff::RedisCacheStore.new(pool, timeout: 7.days, namespace: "t")

# Optional
GoogleTranslateDiff.rate_limiter =
  GoogleTranslateDiff::RedisRateLimiter.new(
    pool, threshold: 8000, interval: 60, namespace: "t"
  )

GoogleTranslateDiff.translate("test translations", from: "en", to: "es")

How it works

  • Text nodes are extracted from HTML.
  • Every text node is split into sentences (using punkt-segmenter gem).
  • Cache is checked for the presence of each sentence (using language couple and a hash of string).
  • Missing sentences are translated via API and cached.
  • Original HTML is recombined from translations and cache data.

NOTE: :from is required param. Cache can not be checked without specifying exact language couple, that's the limitation.

Input

::translate can receive string, array or deep hash and will return the same, but translated.

GoogleTranslateDiff.translate("test", from: "en", to: "es")
GoogleTranslateDiff.translate("test", "language", from: "en", to: "es")
GoogleTranslateDiff.translate(
  { title: "test", values: { type: "frequent" } }, from: "en", to: "es"
)

See GoogleTranslateDiff::Linearizer for details.

HTML

You can pass HTML as like as plain text:

GoogleTranslateDiff.translate("<b>Black</b>", from: "en", to: "es")

Very long texts

Google API has a limitation: query can not be longer than approximately 4 KB. If your text is really that long, multiple queries will be used to translate it automatically.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/gzigzigzeo/google_translate_diff.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].