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

Multiple keys to pick the first that works #1528

Open
Martinspire opened this issue Feb 26, 2025 · 0 comments
Open

Multiple keys to pick the first that works #1528

Martinspire opened this issue Feb 26, 2025 · 0 comments

Comments

@Martinspire
Copy link

Martinspire commented Feb 26, 2025

Current behavior

You can only provide one key to translate. Something I always wanted, is to easily provide an array where it just picks the first value that actually gets a translation.

Expected behavior

For my project I have a lot of small translations that I would want to fall back on to not supply endless lists of repeated values.

So instead of doing {{'my.translation' | translate}}, I want to do something like this {{['some.translation', 'some.other.translation', 'common.translation'] | translate}}. It will be most useful for dynamic translations where values are dropped in from a backend and you need to provide keys to translate. But instead of repeating yourself, you have multiple locations with values where one could pick from.

The current alternative is to do this in the component logic. To translate a key and check whether it was actually translated or not and return another one, etcetera.

What is the motivation / use case for changing the behavior?

Current situation makes things overly complex for implementing translations

How do you think that we should implement this?

Allow arrays in our item we want to translate. If it is an array, try the first value, do we get a valid response? Return that. Is it not present (with or without language fallback), then we go to the second key and so on. And if we still cant find it, we return the regular value.

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

1 participant