Giter Site home page Giter Site logo

translator's Introduction

Translator

This gem adds a button to html elements that have the 'translatable' class. When pressing the button, it will send the text of the element to the /translate url which will send the data to the predefined translator. In the callback, it will update the text of the element with the translated content.

Installation

Add this line to your application’s Gemfile:

gem 'translator', github: 'ipet/translator'

And add the javascript file in app/assets/javascripts/application.js after jQuery.

//= require jquery
//= require translator

Add translator initializer

module Translator
  setup do |config|
    config.user_lang_method = :current_language

    config.callback = proc do |text,from, to|
      # Block that gets called when translating text
      begin
        CustomTranslator.translate(text, from: from, to: to, content_type: 'text/html')
      rescue => e
        "#{e.class.to_s} #{e.message}"
      end
    end
  end
end

ApplicationController method that will be called to detect the language of the user

config.user_lang_method = :method_name

Block that will be called when clicked on the translate button on en element.

config.callback = proc {}

translator's People

Contributors

ipet avatar bluexiphoid avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.