mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
move i18n of UserActions to JS-side and make sentences translatable
This commit is contained in:
@@ -36,7 +36,7 @@ class UserAction < ActiveRecord::Base
|
||||
].each_with_index.to_a.flatten]
|
||||
|
||||
def self.stats(user_id, guardian)
|
||||
results = UserAction.select("action_type, COUNT(*) count, '' AS description")
|
||||
results = UserAction.select("action_type, COUNT(*) count")
|
||||
.joins(:target_topic)
|
||||
.where(user_id: user_id)
|
||||
.group('action_type')
|
||||
@@ -53,9 +53,6 @@ class UserAction < ActiveRecord::Base
|
||||
results = results.to_a
|
||||
|
||||
results.sort! { |a,b| ORDER[a.action_type] <=> ORDER[b.action_type] }
|
||||
results.each do |row|
|
||||
row.description = self.description(row.action_type, detailed: true)
|
||||
end
|
||||
|
||||
results
|
||||
end
|
||||
@@ -122,7 +119,6 @@ JOIN users pu on pu.id = COALESCE(p.user_id, t.user_id)
|
||||
|
||||
data.each do |row|
|
||||
row["action_type"] = row["action_type"].to_i
|
||||
row["description"] = self.description(row["action_type"])
|
||||
row["created_at"] = DateTime.parse(row["created_at"])
|
||||
# we should probably cache the excerpts in the db at some point
|
||||
row["excerpt"] = PrettyText.excerpt(row["cooked"],300) if row["cooked"]
|
||||
@@ -137,60 +133,6 @@ JOIN users pu on pu.id = COALESCE(p.user_id, t.user_id)
|
||||
data
|
||||
end
|
||||
|
||||
def self.description(row, opts = {})
|
||||
t = I18n.t('user_action_descriptions')
|
||||
if opts[:detailed]
|
||||
# will localize as soon as we stablize the names here
|
||||
desc = case row.to_i
|
||||
when BOOKMARK
|
||||
t[:bookmarks]
|
||||
when NEW_TOPIC
|
||||
t[:topics]
|
||||
when WAS_LIKED
|
||||
t[:likes_received]
|
||||
when LIKE
|
||||
t[:likes_given]
|
||||
when RESPONSE
|
||||
t[:responses]
|
||||
when POST
|
||||
t[:posts]
|
||||
when MENTION
|
||||
t[:mentions]
|
||||
when QUOTE
|
||||
t[:quotes]
|
||||
when EDIT
|
||||
t[:edits]
|
||||
when STAR
|
||||
t[:favorites]
|
||||
when NEW_PRIVATE_MESSAGE
|
||||
t[:sent_items]
|
||||
when GOT_PRIVATE_MESSAGE
|
||||
t[:inbox]
|
||||
end
|
||||
else
|
||||
desc =
|
||||
case row.to_i
|
||||
when NEW_TOPIC
|
||||
then t[:posted]
|
||||
when LIKE,WAS_LIKED
|
||||
then t[:liked]
|
||||
when RESPONSE,POST
|
||||
then t[:responded_to]
|
||||
when BOOKMARK
|
||||
then t[:bookmarked]
|
||||
when MENTION
|
||||
then t[:mentioned]
|
||||
when QUOTE
|
||||
then t[:quoted]
|
||||
when STAR
|
||||
then t[:favorited]
|
||||
when EDIT
|
||||
then t[:edited]
|
||||
end
|
||||
end
|
||||
desc
|
||||
end
|
||||
|
||||
def self.log_action!(hash)
|
||||
require_parameters(hash, :action_type, :user_id, :acting_user_id, :target_topic_id, :target_post_id)
|
||||
transaction(requires_new: true) do
|
||||
|
||||
Reference in New Issue
Block a user