-
Notifications
You must be signed in to change notification settings - Fork 897
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
Migrate model display names from locale/en.yml to models #16836
Migrate model display names from locale/en.yml to models #16836
Conversation
5d54487
to
4839295
Compare
4839295
to
66b808b
Compare
Or even @martinpovolny ? |
app/models/container_group.rb
Outdated
@@ -95,4 +95,8 @@ def disconnect_inv | |||
self.deleted_on = Time.now.utc | |||
save | |||
end | |||
|
|||
def self.display_name(number = 1) | |||
n_('Container Pod', 'Container Pods', number) |
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.
Should this just be "Pod" / "Pods"?
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.
Also, note that this term may not apply to other variants in the future, which is why we made the model name generic.
@@ -4,4 +4,8 @@ class ConfigurationScriptSource < ApplicationRecord | |||
belongs_to :manager, :class_name => "ExtManagementSystem" | |||
|
|||
virtual_total :total_payloads, :configuration_script_payloads | |||
|
|||
def self.display_name(number = 1) | |||
n_('Repository', 'Repositories', number) |
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.
Note that this term may not apply to other variants in the future, which is why we made the model name generic. It works for Ansible, but that's not the only thing that can use this table.
@@ -2,4 +2,8 @@ class ContainerGroupPerformance < MetricRollup | |||
default_scope { where("resource_type = 'ContainerGroup' and resource_id IS NOT NULL") } | |||
|
|||
belongs_to :container_group, :foreign_key => :resource_id, :class_name => ContainerGroup.name | |||
|
|||
def self.display_name(number = 1) | |||
n_('Performance - Pod', 'Performance - Pods', number) |
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.
same.
@@ -2,4 +2,8 @@ class ContainerNodePerformance < MetricRollup | |||
default_scope { where("resource_type = 'ContainerNode' and resource_id IS NOT NULL") } | |||
|
|||
belongs_to :container_node, :foreign_key => :resource_id, :class_name => ContainerNode.name | |||
|
|||
def self.display_name(number = 1) | |||
n_('Performance - Container Node', 'Performance - Container Nodes', number) |
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.
Should these be "Container Node Performance" and "Container Node Performances"? I think they are performance records for a single node.
app/models/ems_cluster.rb
Outdated
@@ -336,4 +336,8 @@ def self.non_openstack_clusters_exists? | |||
def openstack_cluster? | |||
ext_management_system.class == ManageIQ::Providers::Openstack::InfraManager | |||
end | |||
|
|||
def self.display_name(number = 1) | |||
n_('Cluster / Deployment Role', 'Cluster / Deployment Roles', number) |
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.
Should the plural be "Clusters / Deployment Roles"?
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.
Shouldn't "Cluster" also be pluralized?
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.
Yes, this has been corrected to 'Clusters / Deployment Roles'
.
@@ -2,4 +2,8 @@ class EmsClusterPerformance < MetricRollup | |||
default_scope { where("resource_type = 'EmsCluster' and resource_id IS NOT NULL") } | |||
|
|||
belongs_to :ems_cluster, :foreign_key => :resource_id | |||
|
|||
def self.display_name(number = 1) | |||
n_('Performance - Cluster', 'Performance - Clusters', number) |
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.
Again, "Cluster Performances"?
app/models/ext_management_system.rb
Outdated
@@ -674,6 +674,10 @@ def tenant_identity | |||
User.super_admin.tap { |u| u.current_group = tenant.default_miq_group } | |||
end | |||
|
|||
def self.display_name(number = 1) | |||
n_('Provider', 'Providers', number) |
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.
This conflicts with the Provider
model. They're not the same thing
The gettext thing is about collecting static strings from the sources. We have strings in the sources. Also we already have these particular static strings in the repository right now. In the YAMLs. Just the placement of these few strings is non-standard and is not pluggable and it requires an extra rake task to collect. Instead of fixing that by moving the strings in the sources (where the other strings already are) you ask to create a new special rake task to collect the strings from the models. Yes, it will work. But no, it's not the default or standard way to do it. Does it have benefits? Well you will not have those methods in core. A method per model. Other benefits? I don't see any. Negative points: an extra rake task + handling some strings differently than others. Furthemore the part:
is simply not true. The method would not be the same. It would contain different strings. |
I'm letting myself out of this PR review. I'm 🤷♀️ with the changes but if others are ok with it once rebased and all questions answered, then I'm 👍 My only comment is, we have what appears to many of us as unnecessary duplication that is hard for people who know our gettext steps to explain. I will continue to look at this code and not understand why the duplication is needed instead of an intermediate step that populates the strings in a pre-gettext step. But alas, I really don't spend time here so it won't bother me that often. |
I'm currently working on a solution (as suggested in previous comments) that would address the duplication concerns. |
c2941d4
to
56fec1a
Compare
Based on the previous discussion, I made the following changes:
|
task "model_display_names" => :environment do | ||
f = File.open(Rails.root.join("config/model_display_names.rb"), "w+") | ||
Rails.application.eager_load! | ||
ApplicationRecord.descendants.sort_by(&:display_name).collect do |model| |
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.
Just a warning... there are some non-ApplicationRecord models. But I do prefer this approach
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.
Is it ok if we're looking for descendants of ApplicationRecord
then?
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 don't know. If you only need a display name for things found in the database, then yes.
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.
Or maybe those non-ApplicationRecord classes are just required to implement the display_name
method. I could be okay with that until we find a better solution.
56fec1a
to
02212ec
Compare
This is what would the new rake task currently produce: https://gist.github.com/mzazrivec/ada935b99a67ceb5014d1893a5b3ec78 |
This pull request is not mergeable. Please rebase and repush. |
02212ec
to
f1d1e0e
Compare
This pull request is not mergeable. Please rebase and repush. |
f1d1e0e
to
4d31b2a
Compare
Some comments on commits mzazrivec/manageiq@cfdd29b~...4d31b2a lib/tasks/locale.rake
|
Checked commits mzazrivec/manageiq@cfdd29b~...4d31b2a with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 lib/tasks/locale.rake
|
This is a continuation of the work started in #16596 where we want to migrate display model names from
locale/en.yml
into particular models, where we'll use standard gettext. Main goal here is to make this one aspect of our application pluggable.The strings were migrated automatically and adjusted where needed (incorrect plurals and such), some of the display names were changed:
Next step would be to switch
ui_lookup()
andDictionary.gettext()
to usedisplay_name()
rather thanI18n.t()
andlocale.en.yml
.Plugin PRs:
ManageIQ/manageiq-automation_engine#145
ManageIQ/manageiq-providers-ansible_tower#55
ManageIQ/manageiq-providers-amazon#398
ManageIQ/manageiq-providers-azure#200
ManageIQ/manageiq-providers-foreman#16
ManageIQ/manageiq-providers-google#42
ManageIQ/manageiq-providers-kubernetes#218
ManageIQ/manageiq-providers-lenovo#126
ManageIQ/manageiq-providers-openshift#84
ManageIQ/manageiq-providers-openstack#200
ManageIQ/manageiq-providers-scvmm#60
ManageIQ/manageiq-providers-vmware#174
ManageIQ/manageiq-providers-ovirt#197
gaprindashvili/no