Open nitsujri opened 8 years ago
+1
@nitsujri What about having
user.set_tag_list_on(:german, 'kein, tag, hier, suche, etc') user.tag_list_on(:german) # german tags by context
user.set_tag_list_on(:english, 'no, tags, fund, here, sorry') user.tag_list_on(:english) # english tags by context
I am of the idea that tags should always be unique and not automatically scoped or translated by the system or it may cause some problem. Let's say you have them translated but you need an api endpoint to retrieve them later (without distiction between english and germans). How would you manage that if they are scoped already? Instead, in that way, you scope them only when you need and re-use that 'context' feature already present in the gem
I overrided some method in the ActsAsTaggableOn::Tag to implement the localization of model Tag, but the name field in the tags table is still blank.
module ActsAsTaggableOn
class Tag < ::ActiveRecord::Base
translates :name,:slug
def cache_key
super + '-' + Globalize.locale.to_s
end
extend FriendlyId
friendly_id :name,:use => [:slugged,:finders,:globalize]
def self.named(name)
if ActsAsTaggableOn.strict_case_match
where(name: as_8bit_ascii(name))
else
where(name: as_8bit_ascii(unicode_downcase(name)))
end
end
def self.named_any(list)
arr = []
list.each do |tag|
t = ActsAsTaggableOn::Tag.where(name: tag).first
arr << t if t.present?
end
return arr
end
end
end
Can yuo put this code on initializer:
module ActsAsTaggableOn class Tag < ::ActiveRecord::Base def self.named_any(list) clause = list.map { |tag| sanitize_sql_for_named_any(tag).force_encoding('BINARY') }.join(' OR ')
joins(:translations).where(clause)
end
private
def self.sanitize_sql_for_named_any(tag)
#raise "#{tag}"
if ActsAsTaggableOn.strict_case_match
sanitize_sql(["tag_translations.name = #{binary}?", as_8bit_ascii(tag)])
else
sanitize_sql(['LOWER(tag_translations.name) = LOWER(?)', as_8bit_ascii(unicode_downcase(tag))])
end
end
end end
@alebacca89 Thanks. That's works only for CRUD tag, but not work tagged_with.
Thanks for this amazing gem.
We translated all of our tags and the migration works great. The trouble we're having now is new tags don't write to the table
tags.name
column. The causes thename
to be blank even though the tag is created the first time.When we try to reuse that tag, because of the blank
name
it runs into problems with:self.find_or_create_all_with_like_by_name(*list)
The hack we built is to run
self.update_columns(name: self.name)
onafter_create
. The issue with this is it requirestag.name
to always be in sync withtag_translation.name
for:en
.What is the best way to use
globalize
? Can the dependence ontags.name
be circumvented or removed?