Home arrow Ruby-on-Rails arrow Page 2 - Getting Text and Currency Working for Multiple Language Support

Getting Text and Currency Working for Multiple Language Support

In this conclusion to a four-part article series on adding support for multiple languages to a Ruby-on-Rails ecomerce application, you will learn how to localize numbers and currency, set character encoding, 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 / 11
July 02, 2010
  1. · Getting Text and Currency Working for Multiple Language Support
  2. · Adding Unicode (UTF-8) Support
  3. · Setting Character Encoding in HTML
  4. · Setting Character Encoding for the HTTP Response
  5. · Changing the Database to Use UTF-8

print this article

Getting Text and Currency Working for Multiple Language Support - Adding Unicode (UTF-8) Support
(Page 2 of 5 )

As we mentioned earlier, George wants to enter the Chinese market sooner or later. In China, the official character set is simplified Chinese, which contains about 6000 different characters. Languages like Simplified Chinese that contain hundreds or thousands of characters do not fit into the standard used by most languages in Europe and North America (ISO-8859-1). Instead, these languages require that we change the application to support UTF-8.

UTF-8 can represent any universal character in the Unicode standard and is backward-compatible with ASCII. UTF-8 is a variable-length character encoding, where each character can be encoded using one to four bytes.

Character encoding is a cause of many problems. For Unicode, or any other character encoding, to work properly, all parts of the system must use the same encoding. In most systems, like Rails-based web applications, this includes the following parts:

  1. The HTML page
  2. The HTTP response headers 
  3. The database 
  4. The database connection

Failing to use the correct character encoding in one or more subsystems usually means that Unicode characters are displayed as question marks or some other invalid character. For example, instead of seeing,

,you would see ??? or some other characters.

Note  The Ruby language doesn't support Unicode out-of-the-box. For example, String#length and String#substr won't work correctly with Unicode strings. See wiki.rubyonrails.com/rails/ pages/HowToUseUnicodeStrings for more information about how to add Unicode support to Ruby.

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-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials