Skip to content

Instantly share code, notes, and snippets.

@descovi
Last active February 9, 2023 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save descovi/f0c5469e2710585fdfd0ef6c2b3ca947 to your computer and use it in GitHub Desktop.
Save descovi/f0c5469e2710585fdfd0ef6c2b3ca947 to your computer and use it in GitHub Desktop.
EasyTranslation - I18n - Alias - Rails - Rubynetti
# Module for easier translation (Easy Translation)
module EasyTranslation
extend ActiveSupport::Concern
included do
def self.t(symbol=nil)
case symbol
when nil
model_name.human
when :plural
model_name.human(count: 2)
else
human_attribute_name(symbol.to_s)
end
end
def self.tt
t(:plural)
end
end
end
@descovi
Copy link
Author

descovi commented Feb 9, 2023

Ticket.t --> "Ticket"
Message.t ---> "Messaggio"
Message.tt ---> "Messaggi"
Ticket.t(:body) --> "corpo"

t('nome della chiave')

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