-
-
Notifications
You must be signed in to change notification settings - Fork 497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't create translation record for default_locale on save #328
Conversation
Thanks, this is interesting and looks sensible. I seem to recall stumbling on a similar problem with @parndt any thoughts? |
I added a couple of tests. They roughly illustrate my problem. In particular, when I try to save Also, if you add any validation into your Translation model, you'll get validation error on save, because you won't be able to save empty translation record for default locale. (This is what I've tried to describe in my first message) |
I had the same problem and there is mini thread #195 #184 about default translation behavior and it's not a bug, it's a feature. So I made micro gem globalize-missing which will allow you save translation without default locale. |
33c41c7
to
2d9c8b6
Compare
I can't stress enough how sorry I am for such a long pause, but I finally have some time to finish or close my pull requests. @jirikolarik I see your point, but #195 doesn't cover all of the issues. In my particular case, I want to save the record with translation for not-default locale (:de in test). Although, now it won't create a translation for default locale on save at all, if we didn't assign any translated attribute. (This is almost exactly the same issue as #195) @shioyama could you take at look at it again, please? |
2d9c8b6
to
e0c31d8
Compare
+1 |
Any news on this ? I'm having the same issue and I have trouble imagining how there could not be an army of people effected by this behavior. Looking at the Travis failure it seems to me that it's related to some testing environment quirks and not to the actual commits discussed here. What do you think ? EDIT: I was just thinking that maybe some (foolish) people would actually rely on this behavior in their application. I that case maybe adding a configuration option like EDIT 2: I'm realizing that the reason I have to fight globalize might be that empty translations are supposed to happen, as pardnt was saying in another issue. I can't take more time on this for today, I'll update with future realizations tomorrow. |
@jerefrer , I'm going through all of it now as well.
You mean this comment #195 (comment) ? Well, we should start with that question then: Do we want to create a Translation object for a default_locale even if we don't use it at all (f.e. it doesnt have any attributes set)? IMHO, I don't see any reasons we should do that. (Of course we can allow it to be configurable with some param, to keep backwards compability) My cases:
|
@scarfacedeb 's fix is working and not really messing up much with the specs. I rebased it in #578 so you can see it. How about somebody gives us a decision what we're gonna do finally about it? ;) |
…lation-on-save Don't create translation record for default_locale on save (globalize#328)
…lation-on-save Don't create translation record for default_locale on save (globalize#328)
Globalize creates a translation for the current locale, and the only way I've found to change this behaviour is to monkey-patch it. See also the following convertations: globalize/globalize#328 globalize/globalize#468 globalize/globalize#578 https://github.com/shioyama/mobility/wiki/Migrating-from-Globalize#blank-translations
Globalize creates a translation for the current locale, and the only way I've found to change this behaviour is to monkey-patch it. See also the following convertations: globalize/globalize#328 globalize/globalize#468 globalize/globalize#578 https://github.com/shioyama/mobility/wiki/Migrating-from-Globalize#blank-translations
Globalize creates a translation for the current locale, and the only way I've found to change this behaviour is to monkey-patch it. The original code uses `translation.locale` instead of `Globalize.locale`. Since `translation.locale` loads the translation with empty attributes. It both makes the record invalid if there are validations and it makes it almost impossible to create a record with translations which don't include the current locale. See also the following convertations: globalize/globalize#328 globalize/globalize#468 globalize/globalize#578 https://github.com/shioyama/mobility/wiki/Migrating-from-Globalize#blank-translations
Globalize creates a translation for the current locale, and the only way I've found to change this behaviour is to monkey-patch it. The original code uses `translation.locale` instead of `Globalize.locale`. Since `translation.locale` loads the translation with empty attributes. It both makes the record invalid if there are validations and it makes it almost impossible to create a record with translations which don't include the current locale. See also the following convertations: globalize/globalize#328 globalize/globalize#468 globalize/globalize#578 https://github.com/shioyama/mobility/wiki/Migrating-from-Globalize#blank-translations
Globalize creates a translation for the current locale, and the only way I've found to change this behaviour is to monkey-patch it. The original code uses `translation.locale` instead of `Globalize.locale`. Since `translation.locale` loads the translation with empty attributes. It both makes the record invalid if there are validations and it makes it almost impossible to create a record with translations which don't include the current locale. See also the following convertations: globalize/globalize#328 globalize/globalize#468 globalize/globalize#578 https://github.com/shioyama/mobility/wiki/Migrating-from-Globalize#blank-translations
Globalize creates a translation for the current locale, and the only way I've found to change this behaviour is to monkey-patch it. The original code uses `translation.locale` instead of `Globalize.locale`. Since `translation.locale` loads the translation with empty attributes. It both makes the record invalid if there are validations and it makes it almost impossible to create a record with translations which don't include the current locale. See also the following convertations: globalize/globalize#328 globalize/globalize#468 globalize/globalize#578 https://github.com/shioyama/mobility/wiki/Migrating-from-Globalize#blank-translations
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I want to allow users to create localized pages for a specific locale, excluding default locale.
That way I can have a czech-specific page only on the czech version of a site.
But I can't do that because when I'm trying to save a new
Page
record with aPage::Translation
association (locale == :cz
), rails gives me a validation error, because globalize has added another association withlocale == :en
.I'm using
rails_admin
and its default field for has_many associations.I think that my problem starts inside
save
method.In particular, this part in
read_attribute
:Which leads to
translation
method:As a result,
translation_for
builds an empty translation for default::Globalize.locale
locale.I think that
read_attribute(:locale)
could skip creating default translation record, because in that particular case it only uses it to get its locale, that is equal toGlobalize.locale
anyway.I ran
rake test
on this branch and on the branch with merged before_callbacks (it's called combined) and there's no new errors.