carlosantoniodasilva/i18n_alchemy

How to localize only specific fields on a model?

Closed this issue · 2 comments

I want to localize my model's numeric fields but not the dates. How I can tell Alchemy that I only want it to operate on fields that I specify?

Unfortunately I don't think this is possible right now, it will automatically work on all your date/time/numeric fields. Are you hitting any issue by making it also work on your date fields?

If you happen to have any idea, please feel free to suggest an implementation / API to make that happen.

I use a javascript date picker which handles the delocalisation for me: it sends back delocalised dates to Rails so I don't want Rails to try to delocalise them again.

Also I don't want nested-attribute associations handled by default. It's great that the code can do it but I'd like to be able to choose whether or not it does.

In terms of an API, I'd probably make the localized method accepts the fields I want handled. For example:

# Default, handles everything
@product.localized

# Only converts the price field
@product.localized :price

Anyway, in my situation I only needs to convert two numeric fields in one model so I have just written a little helper method to do it in that one place.

Thanks!