From benjamin.meichsner at googlemail.com Wed Jul 2 05:46:22 2008 From: benjamin.meichsner at googlemail.com (Benjamin Meichsner) Date: Wed, 2 Jul 2008 11:46:22 +0200 Subject: [Rails I18n] L10n of numbers? In-Reply-To: <6b9e1eb20801070630nf7cad4cm6cb54bc62e1a5162@mail.gmail.com> References: <6b9e1eb20801070630nf7cad4cm6cb54bc62e1a5162@mail.gmail.com> Message-ID: <4bf6e78b309614daeb86300f548db321@ruby-forum.com> Hey Isak, I currently working on the same problem. In my last projects I have workaround with an own setter for the numbers. e.g. the active-record model class Article def price=(value) self.price = value.to_delocalized_decimal end end and the String-class extension: class String def to_delocalized_decimal return self if !self.is_a?(String) or self.blank? BigDecimal.new(string.sub(',', '.')) end end maybe this is usefull for your research-program. But i guess its better to use extra methods to fill your database-field. In this case the output would be also localized. e.g. def localized_price=(value) self.price = value.to_delocalized_decimal end def localized_price price.to_delocalized_decimal # use another BigDecimal-extension end and the premium-version would be an ActiveRecord::Base-extension. Any suggestions how to build such a plugin? cheerio benni -- Posted via http://www.ruby-forum.com/. From jarkko at jlaine.net Wed Jul 2 10:38:11 2008 From: jarkko at jlaine.net (Jarkko Laine) Date: Wed, 2 Jul 2008 17:38:11 +0300 Subject: [Rails I18n] L10n of numbers? In-Reply-To: <4bf6e78b309614daeb86300f548db321@ruby-forum.com> References: <6b9e1eb20801070630nf7cad4cm6cb54bc62e1a5162@mail.gmail.com> <4bf6e78b309614daeb86300f548db321@ruby-forum.com> Message-ID: On 2.7.2008, at 12.46, Benjamin Meichsner wrote: > Hey Isak, > > I currently working on the same problem. In my last projects I have > workaround with an own setter for the numbers. e.g. > > the active-record model > class Article > def price=(value) > self.price = value.to_delocalized_decimal > end > end > > and the String-class extension: > > class String > def to_delocalized_decimal > return self if !self.is_a?(String) or self.blank? > BigDecimal.new(string.sub(',', '.')) > end > end > > maybe this is usefull for your research-program. But i guess its > better > to use extra methods to fill your database-field. In this case the > output would be also localized. e.g. > > def localized_price=(value) > self.price = value.to_delocalized_decimal > end > def localized_price > price.to_delocalized_decimal # use another BigDecimal-extension > end Just curious, but you do realize that to_delocalized_decimal is only defined in the String class? That has two consequences: any other object than a string will throw an exception. That's ok, if you only ever get strings as values. However, in that case (and anyway since you're defining the method in the String class) there's no idea checking whether self is a string in the to_delocalized_decimal method. self.is_a?(String) will always return true when used inside a method of the String class. //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2417 bytes Desc: not available URL: From benjamin.meichsner at googlemail.com Wed Jul 2 14:00:34 2008 From: benjamin.meichsner at googlemail.com (Benjamin Meichsner) Date: Wed, 2 Jul 2008 20:00:34 +0200 Subject: [Rails I18n] L10n of numbers? In-Reply-To: References: <6b9e1eb20801070630nf7cad4cm6cb54bc62e1a5162@mail.gmail.com> <4bf6e78b309614daeb86300f548db321@ruby-forum.com> Message-ID: <805b466659e15bccabb80ce10c65fc05@ruby-forum.com> Hey Jarkko, thanks for your comment. I give it another try: # the extensions class String def to_delocalized_decimal BigDecimal.new(self.sub(',', '.')) rescue self end end class BigDecimal def to_localized_string(precision=2) ("%01.#{precision}f" % self).to_s.sub('.', ',') rescue self.to_s end end # my ActiveRecord-Class class Article < ActiveRecord::Base def localized_price=(value) self.price = value.to_delocalized_decimal unless value.blank? end def localized_price price.to_localized_string if price end end # my new.html.erb ... Price
<%= f.text_field :localized_price %> But I guess, you have a solution more elegant? I'm dreaming of an ActiveRecordPlugin, so I just have to write .. class Article localized_decimal :price, :tax ... end ... and I got the two setter and getter methods for free. Anyone have an idea how to make it? Greetings Benni -- Posted via http://www.ruby-forum.com/. From jarkko at jlaine.net Wed Jul 2 15:19:34 2008 From: jarkko at jlaine.net (Jarkko Laine) Date: Wed, 2 Jul 2008 22:19:34 +0300 Subject: [Rails I18n] L10n of numbers? In-Reply-To: <805b466659e15bccabb80ce10c65fc05@ruby-forum.com> References: <6b9e1eb20801070630nf7cad4cm6cb54bc62e1a5162@mail.gmail.com> <4bf6e78b309614daeb86300f548db321@ruby-forum.com> <805b466659e15bccabb80ce10c65fc05@ruby-forum.com> Message-ID: On 2.7.2008, at 21.00, Benjamin Meichsner wrote: > Hey Jarkko, > thanks for your comment. I give it another try: > > # the extensions > class String > def to_delocalized_decimal > BigDecimal.new(self.sub(',', '.')) > rescue > self > end > end > class BigDecimal > def to_localized_string(precision=2) > ("%01.#{precision}f" % self).to_s.sub('.', ',') > rescue > self.to_s > end > end > > # my ActiveRecord-Class > class Article < ActiveRecord::Base > def localized_price=(value) > self.price = value.to_delocalized_decimal unless value.blank? > end > def localized_price > price.to_localized_string if price > end > end > > # my new.html.erb > ... > Price
> <%= f.text_field :localized_price %> > > But I guess, you have a solution more elegant? I'm dreaming of an > ActiveRecordPlugin, so I just have to write .. Sorry, I've just used a before_save filter defined in AR::Base. It would be fairly easy to make a plugin out of that, all it takes is some metaprogramming skills. If you aren't familiar with metaprogramming in Ruby, I highly recommend PragDave's recent screencasts (http://www.pragprog.com/screencasts/v-dtrubyom/the-ruby-object-model-and-metaprogramming ). They'll cost you $5 a piece, but with the current state of the dollar that's not too much asked imho. Cheers, //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2417 bytes Desc: not available URL: From benjamin.meichsner at googlemail.com Mon Jul 14 09:35:25 2008 From: benjamin.meichsner at googlemail.com (Benjamin Meichsner) Date: Mon, 14 Jul 2008 15:35:25 +0200 Subject: [Rails I18n] parse haml for gettext: RubyLex Error Message-ID: hey I would like to bring the newest versions of haml(2.0.1), rails(2.1.0) and gettext(1.91.0) in my current project together. But in the moment, I failure on parsing the haml-files to update my po-files. This is the error message: ~/dev/GettextTest$ rake updatepo Error: # # the rake task desc "Update pot/po files." task :updatepo do require 'gettext/utils' GetText.update_pofiles("blog", Dir.glob("{app,lib,bin}/**/*.{rb,erb,rjs,haml}"), "blog 1.0.0") end # and the haml-parser require 'gettext/rgettext' module HamlParser module_function def target?(file) File.extname(file) == ".haml" end def parse(file, ary = []) haml = Haml::Engine.new(IO.readlines(file).join) code = haml.precompiled.split(/$/) RubyParser.parse_lines(file, code, ary) end end GetText::RGetText.add_parser(HamlParser) Any idas how to fix it? thanks in advance, Benni -- Posted via http://www.ruby-forum.com/. From cojones at gmx.li Tue Jul 15 03:41:41 2008 From: cojones at gmx.li (Heinz Strunk) Date: Tue, 15 Jul 2008 09:41:41 +0200 Subject: [Rails I18n] Can't get Globalize running... Message-ID: <2d59b37bf4f7a07f7ca20543db246ad9@ruby-forum.com> Hey people, I just imported a rails project to my freshly installed NetBeans (used to use Eclipse before) and tried to "reintegrate" Globalize. I tried it by simply typing "rake globalize:setup" while in projects folder but it doesn't work: Don't know how to build task 'globalize:setup' Does anyone have an idea how to make it work again? Thanks a lot! -- Posted via http://www.ruby-forum.com/. From egoistmb at yahoo.com Fri Jul 18 11:10:31 2008 From: egoistmb at yahoo.com (Egoist Egoist555) Date: Fri, 18 Jul 2008 17:10:31 +0200 Subject: [Rails I18n] Easy Puzzle Mountain problem In-Reply-To: <4146f2425fe37d9a995a9c019889621c@ruby-forum.com> References: <612f46cfd17f46b384849a070fea1166@ruby-forum.com> <4146f2425fe37d9a995a9c019889621c@ruby-forum.com> Message-ID: <68d0b4db011903e50a803c7d031d2884@ruby-forum.com> http://gaffer.ru/index.html http://vnepravil.ru/index.html http://obaldel.ru/index.html http://risovka.ru/index.html http://dotpor.ru/index.html http://bezpontovie.ru/index.html http://vipsek.ru/index.html http://boomsa.ru/index.html http://titkiboo.ru/index.html http://goodeg.ru/index.html http://rubiseks.ru/index.html http://lubiseks.ru/index.html http://seksgun.ru/index.html -- Posted via http://www.ruby-forum.com/. From gigatavu at gmail.com Sat Jul 26 02:06:54 2008 From: gigatavu at gmail.com (Gi Ga) Date: Sat, 26 Jul 2008 08:06:54 +0200 Subject: [Rails I18n] Best way to make multilanguage program Message-ID: In rails 2.2 there will bi new system to translate aplications. But if I start now deviloping a big program, what is the best way to make a multilanguage progrman thinking about future? It will be in 3 languges, english, swedish and russian. -- Posted via http://www.ruby-forum.com/.