Skip to content

Conversation

@andryusha
Copy link
Contributor

No description provided.

@leastbad
Copy link
Owner

leastbad commented Apr 6, 2020

Hey, Andrey! Thanks for taking a look at this.

Could you help me understand your approach, here? I have an admittedly Anglo-centric linguistic outlook, making me spoiled and privileged. I'd love to make this library easy for everyone to work with.

What I know is that Humanize does a reasonably good job on English words for most cases. Plus with the way Inflector is set up, you can add additional words. I have no idea what the situation is for different languages, much less different alphabets or Cyrillic character sets.

The issue is for attributes such as "ssl" or "user id". You want the display to be SSL or User, not Ssl or User id.

So I guess my question is... what about the full_message() method makes it a better candidate for internationalization?

Could we do something like this?

message = "#{model.errors.full_message(attribute.humanize, model.errors.messages[attribute.to_sym].first)}#{Optimism.suffix}"

Would that accomplish the same outcome, or will humanize mess up with other character sets?

@leastbad leastbad merged commit 99b1733 into leastbad:master Apr 6, 2020
@leastbad
Copy link
Owner

leastbad commented Apr 6, 2020

FWIW, I just went for it. 😁

@andryusha
Copy link
Contributor Author

Your solution did not use attribute names from localization files (config/locales/ru.yml for example). And also it did not allow to set a custom format for the error message.

Unfortunately, attribute.humanize and Inflector helps only for English.

@andryusha
Copy link
Contributor Author

andryusha commented Apr 7, 2020

Attribute name still in-english in error message. Solution: attribute.to_sym

https://apidock.com/rails/v6.0.0/ActiveModel/Errors/full_message

@leastbad
Copy link
Owner

leastbad commented Apr 7, 2020

Damn, well... I tried! We will get this working, I promise. I quite literally need your help, though. I had to push a new release yesterday and hoped my fix would work. We can take our time getting this working properly now.

I didn't realize that Inflector didn't work with non-English applications. That honestly really sucks. Weird, too, considering that English is DHH's 2nd language.

So here's what I propose: I will add a new configuration option. (What should I call it? humanize? inflector? english? i18n?) Let's assume for discussion that it will be humanize:

self.humanize = true
...
message = "#{model.errors.full_message(Optimism.humanize ? attribute.humanize : attribute.to_sym, model.errors.messages[attribute.to_sym].first)}#{Optimism.suffix}"

Will that fix the problem? I don't think I use any other inflector methods... I was worried about pluralize but I don't see it used.

Is there anything else I have to do to get it pulling from config/locales?

@andryusha
Copy link
Contributor Author

Hey. I am sure that in this case no additional option is needed.

My solution is universal and can be used both with internationalization and without it. Just use attribute.to_sym as the first parameter for full_message.

For a deeper understanding of how full_message works, I would recommend you to look at the source code of the method. Btw, .humanize used inside full_message.

@leastbad
Copy link
Owner

leastbad commented Apr 8, 2020 via email

@andryusha
Copy link
Contributor Author

andryusha commented Apr 8, 2020

Do not worry about it. Just use my code

In this case I use user_id and SSL as an inflector acronym.

@andryusha
Copy link
Contributor Author

For english

@leastbad
Copy link
Owner

leastbad commented Apr 8, 2020

🤷‍♂

Well, that was embarrassing. You are, of course, 100% right. Thanks for being patient while I was being stubborn and clever.

I will push 0.2.13 soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants