On 25 and 26 march there was an OpenSourceConference - Japan 2005. During it there was also a Ruby meeting with one of the topics "Ruby on Rails". There is a big interest to RoR here, in Japan. We have a lot of interesting conversations withsome good ideas/wishes. Example from one talk with Mr. Masayoshi Takahashi (the japanese below [typed with uppercase] is more to ilustrate the idea, not to proove how pure my japansese skills are) follows. So on the problem: Let''s we have some signup form. We want to display custom messages on the validation error ( the :message => ".." part of validation_....). For example on too short name: :name, :message => "GAMIJIKAI" -> "is short" on validation it will display: "Name GAMIJIKAI" -> "Name is short" There is however two problems with japanese syntax: 1. It''s mixed japanese and english. It''s because (from what I found) the current ActionModel::Base.human_attribute_name just call .humanize, witch in turn just uppercase the first letter and replace _ with spaces 2. There is additional space after Name So the right one is "NAMAEGAWARUI" The question/wish is: * Is it possible to correct this problem with the current framework? I found a full_message function, witch maybe can do it but not sure how. In this case we need to enter the whole message INCLUDING attribute name, like :message => "NAMAEGAWARUI". Partial solution * If not possible what is the good way to do it (Have somebody done already similar thing?) The original Takahashi-san''s idea was to have something like HumanizeAttributesNamesAssociation with syntax like: humanize_attributes_names :name => "NAMAE", :phone => "DENWA" Thought more on this i found the idea above just partialy solve the problem. For example what will happends with bi- or multilanguage sites? What about the additional space after NAMAE? And what about another languages rules? For example in bulgarian it is good to have additional "to" after name ("ime" in bulgarian) something like "imeto" (the name) My idea (just some thoughts, not a real solution): 1. Have some global environment variable like RAILS_LANG to store the current language settings 2. Define in some YAML file (environment.rb or per language ja.yml, bg.yml etc.) the attributes to names mappings. Something like: attribute_name_mapping: jp: name: NAMAE phone: DENWA ... bg: name: IME phone: TELEFON ... 3. changed human_attribute_name() - pseudocode follows def human_attribute_name(...,attr_name) unless attribute_name_mapping[RAILS_LANG][attr_name].exists? attr_name.humanize else attribute_name_mapping[RAILS_LANG][attr_name] end end All opinions/ideas are very welcome. Sorry for the long post.
On Mon, 28 Mar 2005 16:15:15 +0900, Stoyan Zhekov <stoyan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The question/wish is: > * Is it possible to correct this problem with the current framework? I > found a full_message function, witch maybe can do it but not sure how. > In this case we need to enter the whole message INCLUDING attribute > name, like :message => "NAMAEGAWARUI". Partial solution > * If not possible what is the good way to do it (Have somebody done > already similar thing?) > The original Takahashi-san''s idea was to have something like > HumanizeAttributesNamesAssociation with syntax like: > > humanize_attributes_names :name => "NAMAE", :phone => "DENWA"I''ve faced some of the same problems, with some swedish sites I''ve done. My solution was simple (and the fastest one really); I include the (swedish) attribute name in the validation error message, like: validates_presence_of :foo, :msg => ''föö måste anges'' # swedish for "can''t be empty" And then only displaying the error msg, not the attribute name when showing validation errors to the user (from a helper): object.errors.each do |attr_name, message| "<li><#{message}/li>" end Of course, this can lead to some repeating of myself, because of swedish grammar rules, eg, things like "Username" and "The username" should be used depending on different rules, and "username" doesn''t have to be the first word in a sentence. So I could either choose to violate grammar rules or repeat myself a bit. I had to go for the later. I imagine many rails developers creating non-english sites have faced similar problems(?), like you describe I do like the idea of mapping the attrib names easily with something like humanized_attributes_names though.. -- johan-san
> And then only displaying the error msg, not the attribute name when > showing validation errors to the user (from a helper): > object.errors.each do |attr_name, message| > "<li><#{message}/li>" > endIn which method is that included (how you overwrite the original method from ActiveRecord)?
> And then only displaying the error msg, not the attribute name when > showing validation errors to the user (from a helper): > object.errors.each do |attr_name, message| > "<li><#{message}/li>" > endFound it - it''s in collaboa sources isn''t it?
On Mon, 28 Mar 2005 18:19:34 +0900, Stoyan Zhekov <stoyan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > And then only displaying the error msg, not the attribute name when > > showing validation errors to the user (from a helper): > > object.errors.each do |attr_name, message| > > "<li><#{message}/li>" > > end > > Found it - it''s in collaboa sources isn''t it? >Yeah, look in the application_helper[1] for the helper which renders the errors for a given instance, works like error_messages_for. -- johan [1]: http://collaboa.cocoa.se/trac/file/trunk/app/helpers/application_helper.rb
Hello, I''m having same attitude right now like Johan has, only I''m trying to go with grammar mostly by helper methods which chooses best form of word (in czech we have (jablko = apple) 1. jablko 2..4 jablka but 5..infin jablek) or sentence. I have something in head about it, but not sure when I''ll have time to implement them, so if there''s more hands we can make it together. So my ask is: is there need for I8N or we can go that fastes way? -- Pepe On 28.3.2005, at 10:33, Johan Sörensen wrote:> On Mon, 28 Mar 2005 16:15:15 +0900, Stoyan Zhekov <stoyan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> The question/wish is: >> * Is it possible to correct this problem with the current framework? I >> found a full_message function, witch maybe can do it but not sure how. >> In this case we need to enter the whole message INCLUDING attribute >> name, like :message => "NAMAEGAWARUI". Partial solution >> * If not possible what is the good way to do it (Have somebody done >> already similar thing?) >> The original Takahashi-san''s idea was to have something like >> HumanizeAttributesNamesAssociation with syntax like: >> >> humanize_attributes_names :name => "NAMAE", :phone => "DENWA" > > I''ve faced some of the same problems, with some swedish sites I''ve > done. My solution was simple (and the fastest one really); I include > the (swedish) attribute name in the validation error message, like: > validates_presence_of :foo, :msg => ''föö måste anges'' # swedish > for "can''t be empty" > And then only displaying the error msg, not the attribute name when > showing validation errors to the user (from a helper): > object.errors.each do |attr_name, message| > "<li><#{message}/li>" > end > > Of course, this can lead to some repeating of myself, because of > swedish grammar rules, eg, things like "Username" and "The username" > should be used depending on different rules, and "username" doesn''t > have to be the first word in a sentence. > So I could either choose to violate grammar rules or repeat myself a > bit. I had to go for the later. I imagine many rails developers > creating non-english sites have faced similar problems(?), like you > describe > > I do like the idea of mapping the attrib names easily with something > like humanized_attributes_names though.. > > -- johan-san > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Feels like a dream to me - my biggest gripe with all webdev tools today is the way you have to localize your apps. However I am not yet on the level with Ruby to help. However maybe the solution for this kind of problems is to abstract the ''humanization'' (which is a brilliant feat of Rails) into an object which can be swapped depending on the laguage (so if we need word flexion-stemming for Russian or Czech we can just hack it into our own language classes?) On 28-mrt-05, at 23:14, Josef Pospíšil wrote:> Hello, > > I''m having same attitude right now like Johan has, only I''m trying to > go with grammar mostly by helper methods which chooses best form of > word (in czech we have (jablko = apple) 1. jablko 2..4 jablka but > 5..infin jablek) or sentence. I have something in head about it, but > not sure when I''ll have time to implement them, so if there''s more > hands we can make it together. > > So my ask is: is there need for I8N or we can go that fastes way? >-- Julian "Julik" Tarkhanov
Hello, dreaming I''ve managed to get meeting with one of the biggest math-linguist in czech rep. (and we are good at it, maybe cause our language is so hard :-), through one my professor, so I''m collecting my wishes about some more auto-grammar in rails (maybe in some general library). If you got some too (I know you have :-) send it to my address. I think I''ll post my list here before I''ll go there. See ya. -- Ing. Josef Pospisil On 30.3.2005, at 7:13, Julian ''Julik'' Tarkhanov wrote:> Feels like a dream to me - my biggest gripe with all webdev tools > today is the way you have to localize your apps. > However I am not yet on the level with Ruby to help. However maybe the > solution for this kind of problems is to abstract the ''humanization'' > (which is a brilliant feat of Rails) into an object which can be > swapped depending on the laguage (so if we need word flexion-stemming > for Russian or Czech we can just hack it into our own language > classes?) > On 28-mrt-05, at 23:14, Josef Pospíšil wrote: > >> Hello, >> >> I''m having same attitude right now like Johan has, only I''m trying to >> go with grammar mostly by helper methods which chooses best form of >> word (in czech we have (jablko = apple) 1. jablko 2..4 jablka but >> 5..infin jablek) or sentence. I have something in head about it, but >> not sure when I''ll have time to implement them, so if there''s more >> hands we can make it together. >> >> So my ask is: is there need for I8N or we can go that fastes way? >> > > -- > Julian "Julik" Tarkhanov > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >