Project

ottra

0.0
No commit activity in last 3 years
No release in over 3 years
One Translator (gem) To Rule (them) All! Uses various translation gems to do language translating.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Ottra

One Translator To Rule them All!

The Problem

The problem with language translation in ruby right now is that everyone does it differently. If you want to use an external source to translate text in your application then you need to write you code for a specific gem. What do you do if you realize, post implementation, that the gem doesn’t support the language combinations or types that you need? That leaves you in quite a pickle.

The Game Changer

Ottra is different – it uses a bunch of different gems in an attempt to translate your text. When you first create a new instance of Ottra, it runs a test translation to each of the different gems it supports and then orders them by whichever was quickest. Then it goes through each of them trying to translate your text. The best part? You write your code for Ottra and then let the gem handle the oddities among the other gems. It’s that simple.

Sample Code

Default, simple example.

require 'ottra'
t = Ottra.new
puts t.translate_text('Hello world!', 'it')
=> Ciao mondo!

Maybe you only want to translate a single string and then send t off to the garbage collector. It might be best to avoid sorting the translators by speed.

t = Ottra.new({:no_sorting => true})
puts t.translate_text('Hello world!', 'it')
=> Ciao mondo!

If your starting language is not English then you need to specify it as the second parameter.

puts t.translate_text('Ciao mondo!', 'en', 'it')
=> Hello World!

Supported Translation Gems

Currently, Ottra supports shvets-google_translate, googletranslate, and tranexp. There are tons of other translation gems out there, but I haven’t gotten a chance to build in support yet.

But…

Github is social coding! Got a favorite translation gem? Fork this project, add your support, and send me a pull request!

What About Tests?

I didn’t write any.

But But But! That’s Blasphemy!

Too bad. Fork, write, and send me a pull request.

Other Notes

This stuff was originally written as part of the Whatever You Say project (rails app that provides chats with on the fly translation) and then ported to an individual gem. It’s pretty rough around the edges in all aspects. It is missing things like:
1. Tests
2. Installing the supported gems when you install this gem
3. Bacon

Otherwise, it works pretty well. Give it a try and if you find something you can’t/won’t fix then add a github ticket.