Coder Social home page Coder Social logo

has_translations's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

has_translations's Issues

Doesn't work as expected

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"

rails 3 support

is it compatible with rails 3 now?
very good plugin, thanks for that!

attr_accessible and the locale in "all_translations"

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 :)

Returns wrong belongs_to key

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".

directly access to translations

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

:autosave option / has_many options

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

Fallback algorithm

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.