Option to select actual column for default locale without the need to rename it.
Kinaan opened this issue · 11 comments
Hi,
I am currently working on a project with a fairly large code base. We had to implement internationalization and we chose traco, but the need to rename actual columns ( e.g. name to name_en ) involved a code refactor.
Right now, I have monkey patched this gem to handle our situation to deal with default locale without renaming the column. The code is in QA process and will be deployed to production in coming week.
I was thinking if we can introduce it as a configurable option that if user wants to keep the old columns intact for default locale and add new columns with prefix for all other locales, it will help old projects ( like ours ) to use this gem easily without a major refactor.
Also I would be really glad to work on my patch further so it can be contributed to the project.
I have planned on something like this for an initializer file.
Traco.setup do |config|
config.default_column_renamed = false
end
I have forked the project and I will update this issue with the link to relevant commit, shortly, so people can review it.
Right now, current tests are passing with the changes but I will be needing an advice to build a strategy for the test cases with default_column_renamed
set to true
any comments ?
Hi! Sorry, I've been on a long vacation. I'll have a look at this when I get the opportunity – sorry for the wait!
@henrik . No problem. I will be waiting for a feedback. Next step would be to setup specs for the change. I am from minitest background but that won't be an issue.
@Kinaan Alright, I had a look. Sorry for the long delay. Looks like really nice functionality. How would you feel if I experimented with this on my end? I want to explore some different options for implementations and how the config would work.
Sure, go ahead. Let me know if I can be of any help. Btw This configuration structure is inspired from mailboxer.
@Kinaan Thanks! I think I'll have a look on my next work lab day, so hopefully end of this week.
@Kinaan I've now had a look, and it's not something I think I will be adding myself. I'm happy to accept a pull request if it doesn't significantly complicate the existing code.
Some considerations:
- The class methods, like
.locale_columns
, would also need to support this. - It would need tests.
And something else I was thinking about:
Do you feel that a global setting like this is a good path forward? Do you see yourselves keeping the old column names forever, and using that naming convention for new models? E.g. if you would add a new "posts" table, would you be fine to keep using naming like "title", "title_de", "title_fr", where the default locale column is inconsistent?
Another option could be to have a setting per column: you'd specify something like translates :title, no_suffix_in_default_locale: true
for your legacy data, but new data would not work that way. And you could migrate old data, attribute by attribute.
I feel this might be a better path forward, but since I'm not in your situation, I don't know.
Closing this due to lack of follow-up.