Home arrow Ruby-on-Rails arrow Page 2 - Translating a Site for Multiple Language Support

Translating a Site for Multiple Language Support

In this third article in a four-part series on adding support for multiple languages to a Ruby-on-Rails ecomerce application, you will learn how to add a translation to a site, edit the translation, and more. This article is excerpted from chapter 10 of the book Practical Rails Projects, written by Eldon Alameda (Apress; ISBN: 1590597818).

Author Info:
By: Apress Publishing
Rating: 5 stars5 stars5 stars5 stars5 stars / 10
July 01, 2010
  1. · Translating a Site for Multiple Language Support
  2. · Implementing the Edit Translation User Story
  3. · Implementing the Delete Translation User Story
  4. · Translating the Model
  5. · Localizing Dates, Numbers, and Currency

print this article

Translating a Site for Multiple Language Support - Implementing the Edit Translation User Story
(Page 2 of 5 )

The in-place editor uses two actions that are called through Ajax requests: get_translation_text and set_translation_text . Next, add these two actions to the controller ( app/controllers/ admin/translate_controller.rb ):

  def get_translation_text
    @translation = ViewTranslation.find(params[:id])
    render :text => @translation.text || ""

  def set_translation_text
    @translation = ViewTranslation.find(params[:id])
    previous = @translation.text
    @translation.text = params[:value]
    @translation.text = previous unless @translation.save
    render :text => @translation.text || '[no translation]'

The get action is called to retrieve and show the translation for the current record, when the administrator clicks somewhere inside the in-place editor field (in the translation column). The set action is called when the administrator saves the translation by clicking the OK button.

Now clicking the translated text in the translation column opens an in-place editor, which allows you to edit the translation, as shown in Figure 10-5. You can save the changes by clicking the OK button, or cancel them by clicking the Cancel button. You can even open more than one in-place editor at a time.

Figure 10-5.  The in-place editor

blog comments powered by Disqus

- Ruby-on-Rails Faces Second Security Flaw in ...
- Ruby 2.0 Prepped for February 2013 Release
- Why LinkedIn Switched from Ruby on Rails
- Adding Style with Action Pack
- Handling HTML in Templates with Action Pack
- Filters, Controllers and Helpers in Action P...
- Action Pack and Controller Filters
- Action Pack Categories and Events
- Logging Out, Events and Templates with Actio...
- Action Pack Sessions and Architecture
- More on Action Pack Partial Templates
- Action Pack Partial Templates
- Displaying Error Messages with the Action Pa...
- Action Pack Request Parameters
- Creating an Action Pack Registration Form

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials