-
Notifications
You must be signed in to change notification settings - Fork 900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ActiveRecord extension for pluggable human model names #16596
ActiveRecord extension for pluggable human model names #16596
Conversation
297b27d
to
a67a892
Compare
I like this proposal ❤️
|
LGTM as well 👍 The only thing.. will this work together well with rails reloads in devel mode? Shouldn't this be a part of |
@chessbyte @Fryguy What do you guys think of this? What do you think about the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like where this is headed, but I have a comments:
- I'd prefer to put this in ApplicationRecord since nothing should inherit directly from
ActiveRecord::Base
- There are some models that don't inherit from ApplicationRecord (they're not backed by the database). As a first pass, I probably wouldn't worry about those.
- I don't like the instance method. The class name isn't accessible directly off of the instance, instead you would do
instance.class.name
and I think this should behave similarly (only implement it on the class). - Is there any way to get rid of the parameter?
- Should it be called
display_name
?
What do you mean by that? How do you provide the count of items w/o the parameter? |
@martinpovolny It feels strange to me to have the pluralization logic in the class since i think of that as a presentation detail. Are there some examples of the callers? Maybe that would help clear up where the pluralization logic belongs. |
I just noticed it now, but I also don't like the translation being here. |
The thing with the plural here is that we simply have to have Other than this I don't have problem with the changes requested here. |
Also, regarding the argument that this is just a presentation detail -- ordinarily I would not do this change in core. I would simply include these model names into the decorator classes that we use in ui-classic. But since |
EDIT: I misread this as an extension to ActiveRecord, so ignore this. |
Can we discuss this then? There a bunch of places where we translate exceptions, which makes no sense. If we get diagnostic logs in a language we don't speak, how are we supposed to diagnose the problem? I think the reason it was done is because the UI takes Exception objects and presents them directly in the UI, but if that's the reason, is there a better way this can be done? |
Can we rather stick to the topic of the PR? We are not trying to change how exceptions are being translated. Also we are not working on removing the translation process from the backend in this PR.
This ^^^ is not about exceptions. There are many translations in the core and in the providers. There's a number of goals explained in the description or this PR. Also we are trying to limit the number of different ways how translations are made. This PR is a part of the i18n effort that is in progress for some time and we should finish it. @bdunne :
The strings for translations are in the core repo. And they are in the core repo in different places in different forms. What this PR is trying to do is to actually limit the number of different forms that these strings have. If the next step would be to remove the strings from this repo then this next step will actually be simpler because of the work done in this PR and follow up PRs that will lead to removal of the As @mzazrivec wrote, the methods that we need for translations of model names could live in some decorators. That can be done in the UI repo. But not right now. Right now, the core repo and the providers use the translations. @mzazrivec has been removing some translations even from the API repo last week. |
@martinpovolny I hope my review didn't come across the wrong way because I really do like the idea of the models having a display name and implementing that in ApplicationRecord (with overrides) makes perfect sense. |
@martinpovolny I am...just because I want to discuss something, doesn't mean I won't let this PR move forward. (FWIW, I think this PR is good, and I'd approve if it aside from the direct modifications to ActiveRecord::Base). However, after discussing we may feel that this PR is not enough, the wrong direction...could be anything. Also, I'm curious about what the backend translations are for to begin with...I was under the impression that most were translated exceptions, so even the fact that you've told me they aren't is more info than I had before for making a decision. 😄
@bdunne It's not a presentation detail, it's fundamental to translating something. You need to know what kind of plural you want, and how many, as some languages have different plural forms depending on the number of objects. You could maybe argue that translations, in general, are a presentation detail, but you can't single out the pluralization part of it. |
Also, I don't see why this can't be gaprindashvili/yes. It doesn't really change anything, and if you end up backporting something, then the translations would just work. Or does the
cause it to be gaprindashvili/no ? |
My primary motivation for this PR was to get rid of As things are, the model names have to be translatable, so I have to use gettext here. This really is not changing compared to what we have now: we do translate model names now as well, we just do it in a non-standard way. The fact that I get to use I certainly understand the point that this is may seem like a presentation detail and normally I would do this in ui-classic in model decorators. But that's not possible at this moment, since there are some The part about logging localized (or partly localized) content: yes, that should not be happening and I'll be happy to look at the problem and fix it. Why gaprindashvili/no -- the fact that this would change how we translate models ( Regarding the general directions and big picture: we're heading towards a concept of UI built on top of rest API, right? The current concept is that the API would not be sending translated strings. This doesn't mean there won't be any gettext in the core though: the strings still will have to be at least marked for translation (with |
That would likely involve adding extra work to the translator teams. |
a67a892
to
c59e45a
Compare
I made the changes as Brandon suggested:
|
Checked commit mzazrivec@c59e45a with ruby 2.3.3, rubocop 0.47.1, haml-lint 0.20.0, and yamllint 1.10.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm good with this for now 👍 Thnaks @mzazrivec
Currently, we store human readable / understandable model names in
locale/en.yml
undermodel:
subtree. On top of this, we haveDictionary.gettext()
andui_lookup()
to return a nice looking model name for given model / class.Problem with this implementation is:
What this PR proposes is an extension to
ActiveRecord
: class & instance methodhuman_model_name()
, which would, for given class or class instance, return human looking model name. The extension itself would obviously be just a fallback, every model would have to override this method on its own:and with the following change in
app/models/miq_report.rb
:we'd see:
PR migrating current content of
locale/en.yml
into models would come separately.