0

I want to print text/characters in Hindi/Sanskrit language.Can anybody guide me using Ruby language how can I achieve this? Are there any libraries/gems available to achieve this? I tried searching for this but could not find desired resources.Basically various webistes displays its contents in Hindi, Gujarati, Sanskrit etc languages but I guess that rendering task is done by browser using font files.Using a programming language how we can achieve the same?

Thanks.

Jignesh Gohel
  • 6,236
  • 6
  • 53
  • 89
  • Printing glyphs in various languages, either on the screen or a printer, is not just the responsibility of a programming language like Ruby. It's also the fonts available to your browser, terminal program or printer, because those convert the flow of binary data from the program into human-recognizable images of characters. Your question involves a huge number of other factors, but you didn't give us enough detail to know how to answer. Encoding is part of it, but not all. – the Tin Man Dec 19 '12 at 20:37

3 Answers3

1

It's nout about the server-side language - it's about using the proper character encoding for your data. UTF-8 is the most common format used to support international languages. Most of India is covered. The browser does all the work and no font additions are required (unless you're getting really fancy with the typography).

उदाहरण के लिये

See: http://www.unicode.org/standard/supported.html

Diodeus - James MacFarlane
  • 112,730
  • 33
  • 157
  • 176
1

In ruby we have [ ].pack('U*') method which converts the given array's value(as Unicode values) to corresponding characters and "XYZ".unpack('U*') which returns me the Unicode values of each characters. After executing,

[2309].pack('U*')

I got Let's understand it with an example, I want मिरो में आपके लिए एक नया सिलाई आदेश Then execute

"मिरो में आपके लिए एक नया सिलाई आदेश".unpack('U*')

This will return me Unicode values of each character of above string.

[32, 2350, 2375, 2306, 32, 2310, 2346, 2325, 2375, 32, 2354, 2367, 2319, 32, 2319, 2325, 32, 2344, 2351, 2366, 32, 2360, 2367, 2354, 2366, 2312, 32, 2310, 2342, 2375, 2358]

Then to regenerate the above Hindi string,

[2350, 2367, 2352, 2379, 32, 2350, 2375, 2306, 32, 2310, 2346, 2325, 2375, 32, 2354, 2367, 2319, 32, 2319, 2325, 32, 2344, 2351, 2366, 32, 2360, 2367, 2354, 2366, 2312, 32, 2310, 2342, 2375, 2358].pack('U*')

Note: .unpack('U*') return's unicode since we asked for it by mentioning 'U*', This unpack/pack methods are also works for binary and many other forms.

Read more about pack/unpack

shubham mishra
  • 1,183
  • 14
  • 21
0

You need to use the right encoding, which for interoperability, is UTF-8. To use UTF-8 in your program you need to add the following comment at the top of your file:

#encoding: utf-8

Then, you need to use your text editors way of inserting symbols in in Hindi or other languages into strings, and Ruby will happily print them.

Linuxios
  • 34,849
  • 13
  • 91
  • 116