Locale number formatting

I've searched and searched for this and have not found an answer.

ruby 1.9.3p194 (2012-04-20) [i386-mingw32]
MSWindows 7

How do you format a number to a current locale? (ie: 1000 -> 1,000 for
'en')

I found the gem package "locale" (locale-2.0.5), but after installation
the advised simplest example in the HowTo:

···

----------------------
require 'locale'

Locale.current
----------------------

displays when run

----------------------
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
require': cannot load such file -- dl/win32 (LoadError)
        from
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
`require'
        from
C:/Ruby193/lib/ruby/site_ruby/1.9.1/locale/driver/win32.rb:16:in `<top
(required)>'
        from
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
`require'
        from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems
custom_require.rb:36:in `require'
        from C:/Ruby193/lib/ruby/site_ruby/1.9.1/locale.rb:32:in
`require_driver'
        from C:/Ruby193/lib/ruby/site_ruby/1.9.1/locale.rb:74:in `init'
        from C:/Ruby193/lib/ruby/site_ruby/1.9.1/locale.rb:90:in
`driver_module'
        from C:/Ruby193/lib/ruby/site_ruby/1.9.1/locale.rb:178:in
`current'
        from C:/Ruby193/lib/ruby/site_ruby/1.9.1/locale.rb:212:in
`candidates'
        from locale.rb:4:in `<main>'
----------------------

Even so, the description of the package leaves no clue as to how or even
if this package provides a way to format data to a locale.

Any help with this would be greatly appreciated.

--
Posted via http://www.ruby-forum.com/.

No answers? For such an incredibly common and required function?
Really??

After a far-too-long search through web pages, blogs, and gem packages,
I can now definitively say that this is one of the worst documented
languages in history.

It seems, no guarantee here, that localization has centered around the
R18n package found at "http://r18n.rubyforge.org/". Again, the
documentation sucks.

Apparently they refer to a standard Ruby interpreter (No Rails, Sinatra,
etc.) as a "desktop" installation. You can install the package via gem
with "gem install r18n-desktop". It will install two packages and will
gack on the documentation with conversion errors (It seems a Ruby 1.9.x
thing. I still have no idea why.).

The attached ruby script demonstrates locale data formatting (Not
documented on the site). This will automatically create an 'i18n' helper
object, configured to the current locale, with an 'l()' method that
performs the locale formatting of a given object.

···

--------------------------------------
Output for a en-US locale

Locale: American English
12,345,678.9
05/15/2012 04:06 PM
--------------------------------------
Output for a de-DE locale

Locale: de_de
12.345.678,9
15.05.2012 16:30
--------------------------------------
I do not know why there is no localized title for the de-DE locale. Seem
kind of insulting.

I have no idea if there are any difference between the 'i18n' and 'r18n'
objects. The 'r18n' object can be used in place of the 'i18n' object in
the attached script with the same results.

So, at least this works and does the desired job. Hopefully this will
save someone else from unnecessarily burning man-hours like I had to.

Enjoy!

Attachments:
http://www.ruby-forum.com/attachment/7393/R18n_Example.rb

--
Posted via http://www.ruby-forum.com/.

Thanks for following up! I just checked, and your post comes up as the
third google hit for "ruby number locale", so as you say, hopefully
the next person down the line will have an easier time.

martin

···

On Tue, May 15, 2012 at 4:45 PM, Llelan D. <lists@ruby-forum.com> wrote:

No answers? For such an incredibly common and required function?
Really??

After a far-too-long search through web pages, blogs, and gem packages,
I can now definitively say that this is one of the worst documented
languages in history.

It seems, no guarantee here, that localization has centered around the
R18n package found at "http://r18n.rubyforge.org/&quot;\. Again, the
documentation sucks.

Apparently they refer to a standard Ruby interpreter (No Rails, Sinatra,
etc.) as a "desktop" installation. You can install the package via gem
with "gem install r18n-desktop". It will install two packages and will
gack on the documentation with conversion errors (It seems a Ruby 1.9.x
thing. I still have no idea why.).

The attached ruby script demonstrates locale data formatting (Not
documented on the site). This will automatically create an 'i18n' helper
object, configured to the current locale, with an 'l()' method that
performs the locale formatting of a given object.

--------------------------------------
Output for a en-US locale

Locale: American English
12,345,678.9
05/15/2012 04:06 PM
--------------------------------------
Output for a de-DE locale

Locale: de_de
12.345.678,9
15.05.2012 16:30
--------------------------------------
I do not know why there is no localized title for the de-DE locale. Seem
kind of insulting.

I have no idea if there are any difference between the 'i18n' and 'r18n'
objects. The 'r18n' object can be used in place of the 'i18n' object in
the attached script with the same results.

So, at least this works and does the desired job. Hopefully this will
save someone else from unnecessarily burning man-hours like I had to.

Enjoy!

Attachments:
http://www.ruby-forum.com/attachment/7393/R18n_Example.rb

--
Posted via http://www.ruby-forum.com/\.