globalize / globalize-accessors

Easily access (read and write) globalize translated fields without fiddling with locale
Other
110 stars 43 forks source link

Not creating translations after saving for empty values #14

Closed eljojo closed 10 years ago

eljojo commented 10 years ago

Hi, if an accessor is used to set an empty value the translation is still created after saving, because write_attribute is still being called.

this fixes that behaviour.

eljojo commented 10 years ago

Hmmm, thinking back about it, this has the drawback that translations will not be able to be set empty again. please don't merge this.

parndt commented 10 years ago

cool, I won't

eljojo commented 10 years ago

ok, I fixed the bug and at the same time fixed another bug. I noticed the system wasn't able to set translations back to an empty value. This test (just wrote it) wasn't passing:

test "not persisted translations can be set to empty values" do
  u = Unit.new(:name_en => "test")
  u.name_en = ""
  assert_equal "", u.translations.first.name
end

What I don't get is the different behaviour of globalize in rails 3 and rails 4. In rails 4, it always creates a translation for for the default locale, whereas in rails 3 it doesn't create any.

eljojo commented 10 years ago

ok, so I changed the test. It will make sure that the polish translation is not created, regardless of the english one.

eljojo commented 10 years ago

fixed!

parndt commented 10 years ago

Thanks!