{"id":16487428,"url":"https://github.com/gzigzigzeo/google_translate_diff","last_synced_at":"2025-03-16T18:31:49.253Z","repository":{"id":45947096,"uuid":"83615500","full_name":"gzigzigzeo/google_translate_diff","owner":"gzigzigzeo","description":"Google Translate API wrapper translates only changes between revisions of big texts","archived":false,"fork":false,"pushed_at":"2021-11-25T13:12:16.000Z","size":58,"stargazers_count":55,"open_issues_count":3,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-27T12:15:44.441Z","etag":null,"topics":["google-cloud","google-translate","google-translator","translation","translation-service"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gzigzigzeo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-02T00:25:46.000Z","updated_at":"2023-06-02T18:49:21.000Z","dependencies_parsed_at":"2022-08-20T22:30:47.400Z","dependency_job_id":null,"html_url":"https://github.com/gzigzigzeo/google_translate_diff","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gzigzigzeo%2Fgoogle_translate_diff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gzigzigzeo%2Fgoogle_translate_diff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gzigzigzeo%2Fgoogle_translate_diff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gzigzigzeo%2Fgoogle_translate_diff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gzigzigzeo","download_url":"https://codeload.github.com/gzigzigzeo/google_translate_diff/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243826783,"owners_count":20354220,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["google-cloud","google-translate","google-translator","translation","translation-service"],"created_at":"2024-10-11T13:34:15.627Z","updated_at":"2025-03-16T18:31:48.554Z","avatar_url":"https://github.com/gzigzigzeo.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GoogleTranslateDiff\n\nGoogle Translate API wrapper helps to translate only changes between revisions of long texts.\n\n\u003ca href=\"https://evilmartians.com/?utm_source=google_translate_diff-gem\"\u003e\n\u003cimg src=\"https://evilmartians.com/badges/sponsored-by-evil-martians.svg\" alt=\"Sponsored by Evil Martians\" width=\"236\" height=\"54\"\u003e\n\u003c/a\u003e\n\n[![Build Status](https://travis-ci.org/gzigzigzeo/google_translate_diff.svg?branch=master)](https://travis-ci.org/gzigzigzeo/google_translate_diff) [![Code Climate](https://codeclimate.com/github/gzigzigzeo/google_translate_diff/badges/gpa.svg)](https://codeclimate.com/github/gzigzigzeo/google_translate_diff) [![Test Coverage](https://codeclimate.com/github/gzigzigzeo/google_translate_diff/badges/coverage.svg)](https://codeclimate.com/github/gzigzigzeo/google_translate_diff/coverage)\n\n## Use case\n\nAssume your project contains a significant amount of products descriptions which:\n- Require retranslation each time user edits them.\n- Have a lot of equal parts (like return policy).\n- Change frequently.\n\nIf your user changes a single word within the long description, you will be charged for the retranslation of the whole text.\n\nMuch 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.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'google_translate_diff'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install google_translate_diff\n\n## Usage\n\n```ruby\nrequire \"google_translate_diff\"\n\n# This dependencies are not included, as you might need to roll your own cache based on different store\nrequire \"redis\"\nrequire \"connection_pool\"\nrequire \"redis-namespace\"\nrequire \"ratelimit\" # Optional, if you will use\n\n# Setup https://github.com/GoogleCloudPlatform/google-cloud-ruby/tree/master/google-cloud-translate\nENV[\"TRANSLATE_KEY\"] = \"foobarkey\"\n\n# I always use pool for redis\npool = ConnectionPool.new(size: 10, timeout: 5) { Redis.new }\n\n# Pass any options (like app id)\nGoogleTranslateDiff.api = Google::Cloud::Translate.new\n\nGoogleTranslateDiff.cache_store =\n  GoogleTranslateDiff::RedisCacheStore.new(pool, timeout: 7.days, namespace: \"t\")\n\n# Optional\nGoogleTranslateDiff.rate_limiter =\n  GoogleTranslateDiff::RedisRateLimiter.new(\n    pool, threshold: 8000, interval: 60, namespace: \"t\"\n  )\n\nGoogleTranslateDiff.translate(\"test translations\", from: \"en\", to: \"es\")\n```\n\n## How it works\n\n- Text nodes are extracted from HTML.\n- Every text node is split into sentences (using `punkt-segmenter` gem).\n- Cache is checked for the presence of each sentence (using language couple and a hash of string).\n- Missing sentences are translated via API and cached.\n- Original HTML is recombined from translations and cache data.\n\n*NOTE:* `:from` is required param. Cache can not be checked without specifying exact language couple, that's the limitation.\n\n## Input\n\n`::translate` can receive string, array or deep hash and will return the same, but translated.\n\n```ruby\nGoogleTranslateDiff.translate(\"test\", from: \"en\", to: \"es\")\nGoogleTranslateDiff.translate(\"test\", \"language\", from: \"en\", to: \"es\")\nGoogleTranslateDiff.translate(\n  { title: \"test\", values: { type: \"frequent\" } }, from: \"en\", to: \"es\"\n)\n```\n\nSee `GoogleTranslateDiff::Linearizer` for details.\n\n## HTML\n\nYou can pass HTML as like as plain text:\n\n```ruby\nGoogleTranslateDiff.translate(\"\u003cb\u003eBlack\u003c/b\u003e\", from: \"en\", to: \"es\")\n```\n\n## Very long texts\n\nGoogle 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.\n\n## Development\n\nAfter 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.\n\nTo 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](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/gzigzigzeo/google_translate_diff.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgzigzigzeo%2Fgoogle_translate_diff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgzigzigzeo%2Fgoogle_translate_diff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgzigzigzeo%2Fgoogle_translate_diff/lists"}