Skip to content
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

Column fallback to original value every time there's no translation present #645

Open
benoror opened this issue Aug 16, 2024 · 3 comments
Open

Comments

@benoror
Copy link

benoror commented Aug 16, 2024

I stumbled upon ColumnFallback (#512 (comment)) which mostly meets our needs, except for one small tangent:

Expected Behavior

TL;DR; Wondering if there's a clean way to default to column value every time there's a missing translation, including for I18n.default_locale.

Full Context:

At my project we currently have a huge set of tables with content that hasn't been translated, we would like to have a default_locale and other available languages but we're having second thoughts of the redundancy of copying over / regenerating the very same content all over again to the translation tables, hence we would like to default to the original value always, unless there's an explicit translation present, independently of the locale (as said before, even default_locale)

Actual Behavior

column_fallback true

It always fallbacks to looking at the translated value except for default_locale

Possible Fix

A) Workaround

Possibly using a Proc for the plugin value with custom logic?

B) Code feature (if ever gets contemplated):

In the original implementation I suppose the change would be somewhere around here:

locale == I18n.default_locale ? model.read_attribute(attribute) : super

...to always call super?

I haven't dig into the newer implementation tho

@benoror benoror changed the title Column fallback to original value always (not default_locale) Column fallback to original value anytime there's no translation present Aug 17, 2024
@benoror benoror changed the title Column fallback to original value anytime there's no translation present Column fallback to original value every time there's no translation present Aug 17, 2024
@benoror
Copy link
Author

benoror commented Aug 17, 2024

OK easiest fix for A) is as simple as:

    column_fallback ->(locale) {
      I18n.available_locales
    }

this is simple enough that might not merit a full blown feature.

closing it now

@benoror benoror closed this as completed Aug 17, 2024
@benoror
Copy link
Author

benoror commented Aug 17, 2024

I am so dumb, that effectively disables Mobility all together 🙈

Going back to square one, wondering if there's a way to check wether the translation exists or not within that Proc 🤔

@benoror benoror reopened this Aug 17, 2024
@mclaros
Copy link

mclaros commented Sep 6, 2024

@benoror I'm not sure I understand your question, but I'm pretty sure that lambda needs to return a boolean. A truthy result would tell Mobility to go ahead and fallback to the original column.

For example, I have a use case where I want Mobility to always fallback for English locales, regardless of region, so here's what I set:

# NOTE: Prior to Mobility, all table column values have been in English, without
# regional differences. We want the Mobility to ignore handling 'en' content as
# translations and instead read/write to the original columns.
column_fallback -> (locale) { locale.to_s.starts_with?('en') }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants