dmitry / has_translations Goto Github PK
View Code? Open in Web Editor NEWActiveRecord plugin to create translations for your models.
License: MIT License
ActiveRecord plugin to create translations for your models.
License: MIT License
I have simple Article with title and body, but after creating item it's title is empty:
>> a = Article.create :title => "EN title"
=> #<Article id: 1, title: "EN title", body: nil, created_at: "2010-10-12 16:41:05", updated_at: "2010-10-12 16:41:05">
>> a.title
=> ""
>> I18n.available_locales
=> [:en, :lv, :ru]
>> I18n.locale
=> :en
>> a[:title]
=> "EN title"
For compatibility with formtastic / form helper methods
See https://github.com/rails/rails/blob/master/actionpack/lib/action_view/helpers/form_helper.rb#L1134
is it compatible with rails 3 now?
very good plugin, thanks for that!
Hi
Could you please merge this change :
https://github.com/artworklv/has_translations/commit/28c0f6bdf76012dc9163842de7ff58cae110458d
into your repo which is fixing the odd scope problem with ruby 1.9.2 , unless you know what is causing it :)
Hi
There is a small problem with your code which is quite tricky to notice at first.
If you will use the attr_accessible than the "all_translations" is returning the new translation objects without the :locale set properly.
Lets say you have 2 locales [ :en, :pl ] and Stock model:
class Stock
attr_accessible :title
translations :title
end
and you do something like this:
Stock.new.all_translations
Than you get :
{:en=>#<StockTranslation id: nil, stock_id: nil, locale: nil, title: nil, created_at: nil, updated_at: nil>, :pl=>#<StockTranslation id: nil, stock_id: nil, locale: nil, title: nil, created_at: nil, updated_at: nil>}
but you should get something like this:
{:en=>#<StockTranslation id: nil, stock_id: nil, locale: "en", title: nil, created_at: nil, updated_at: nil>, :pl=>#<StockTranslation id: nil, stock_id: nil, locale: "pl", title: nil, created_at: nil, updated_at: nil>}
the problem is that in this line (has_translations / lib / has_translations.rb line 100):
find_translation(locale) || (build ? self.translations.build(:locale => locale) : self.translations.new(:locale => locale))
you use mass assignement which prevents the assignement of locale to new objects
I think it would be good to have it fixed in the main repo which is yours :)
In line 93:
belongs_to = self.model_name.demodulize.singularize.underscore.to_sym
For model "MetaData" it returns ":meta_datum" what is wrong, it should be :meta_data. To fix this just remove the "singularize".
Hey guys,
it's not an issue, but i want to as if it's possible to acces the translations of an attribute directly via method call.
when i have this model:
class Horse < ActiveRecord::Base
translations :description, :fallback => true
end
Is there a possibility to acces for example the english translation via:
Horse.last.description_en
Is there a feature like this already implemented or do you think it is helpful? When not, i'll try to find a solution on my own :)
cheers
You can't pass options to the has_many relationship. We'd like to use :autosave.
In our cases we use :writer => true, but save is not invoked for saved objects.
Quoting from http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-has_many
:autosave
If true, always save the associated objects or destroy them if marked for destruction,
when saving the parent object. If false, never save or destroy the associated objects.
By default, only save associated objects that are new records.
By default, only save associated objects that are new records.
:autosave => true # forces the child object to always have with the parent
I worked around this by hi-hacking the relationship in before the AR callback:
eg:
has_many :translations, :class_name => "OfferTranslation", :dependent => :destroy, :autosave => true
# We hi-jack the has_many so we can force :autosave => true before has_translations can define it's has_many without :autosave
translations :title
Hi,
While seeding the database (with english default language) table get's populated in english, but it has no translations. If we add translations, but ask for some attribute in the default language, the first translation will get listed instead of the "default" english one.
Shouldn't it show the original's table attribute? For now I'll copy english translations on seeds, but if you agree I'll make the change so you can merge it.
Thank you in advance,
Tute.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.