https://avo.cool logo
Hello there! I'm trying out Avo for a client pr...
# feedback
b
Hello there! I'm trying out Avo for a client project (to replace ActiveAdmin), I'll probably be giving some feedback as I go on 🙂 First bit about [I18n](https://docs.avohq.io/3.0/i18n.html): why doesn't Avo use
activerecord.models.[model]
by default for
translation_key
? All my models names are already translated there, per Rails' convention.
m
Thread automatically created by Hans in #feedback
b
Also, I think you could define a convention such as
avo.resources.descriptions.[resource]
for defining descriptions from locale files, instead of manually setting
self.description
in the resource
l
regarding `activerecord.models.[model]`: yeah, we had this conversation before in a GH thread
... first, thanks for joining here and sharing the feedback. we love that
the reason why we don't fall to that pattern is that in Avo you may have one model and multiple resources for the same one
for example, you might have one
Comment
model with a
Comment
resource and use a translation for that and if you want to do something more specific in an association or you have a more exotic use-case, you may create a new resource for that model
PhotoComment
with it's own fields, actions, and translations
in hindsight, we could have a toggle somewhere that says, by default use Rails' defaults and if you toggle this on, use Avo's
this is a great suggestion as well. and if it's
nil
, it doesn't show anything
regarding this, does Rails use any specific convention we could hook into, or should we just build our own?
b
I'd say most of the time 1 Model = 1 Resource so it could be helpful (and feel like "magic") if translations tap into the rails conventions by default, then if you're doing something more advanced you can totally define your own
self.translation_key
Same goes for the fields that match model's attributes, Avo could try using
activerecord.attributes.[model].[attribute]
l
yeah. we need a nice way around those
something that's easily changeable
b
It could go like this: given a resource
Company
, - use
self.translation_key
if defined - fallback to
avo.resource_translations.company
- fallback to
activerecord.models.company
- fallback to
Company
.to_s
none that I know of
l
do you know if Rails permits an "automatic" fallback?
for i18n keys
b
l
so it would be something like
Copy code
ruby
t(self.translation_key, default: ["avo.resource_translations.company", "activerecord.models.company", Company.to_s])
b
no, it has to be a symbol > If the :default value is a Symbol, it will be used as a key and translated. One can provide multiple values as default. The first one that results in a value will be returned.
so:
Copy code
rb
t(self.translation_key, default: [:"avo.resource_translations.company", :"activerecord.models.company", Company.to_s])
l
oh yeah
thanks!
l
I wrote a medium-to-large response here and missed the send button 🤦 I'm late now 😂 In my message, I also wrote that Avo mostly relies on resources instead of models, and I think the current translation approach should remain unchanged. However, adding
activerecord.models.***
to the chain would be a great enhancement!