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

Feature(scope): transpile function arguments in FunctionalTranspiler #829

Open
1 task done
f-aubert opened this issue Jan 15, 2025 · 2 comments
Open
1 task done

Comments

@f-aubert
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Which Transloco package(s) will this feature affect?

Transloco

Is your feature request related to a problem? Please describe

No response

Describe the solution you'd like

Each argument of a function should be transpilled, which would allow to define more flexible/generic functions

Describe alternatives you've considered

A less comfortable alternative would be to write more functions which in turn would evaluate its argument surrounding it with interpolation.

Additional context

No response

I would like to make a pull request for this feature

Yes 🚀

f-aubert pushed a commit to f-aubert/transloco that referenced this issue Jan 15, 2025
@shaharkazaz
Copy link
Collaborator

@f-aubert This is a breaking change, can you please elaborate on the use-case with an example? this isn't very descriptive

@f-aubert
Copy link
Author

f-aubert commented Mar 3, 2025

Use-Case:
We have a 'Person' model with a name, a lastLogin timestamp, and a favorite dateFormat for the person. The Translation team would like to display a translated welcome message for the Person.
person = { name: 'John', lastLogin: '2025-02-14T20:14:14', preferredDateFormat: 'dd.MM.yyyy HH:mm' }
{{ 'personSummary' | transloco: person }}

given a provided FunctionalTranspiler function 'formatDate,' and the following translation (english).
personSummary: 'Welcome {{name}}, your last login [[formatDate({{lastLogin}},{{preferredDateFormat}})].'

it should display "Welcome John, your last login 14.02.2025 20:14."

Note: it should not be a breaking change since transpiling something without curly braces or square brackets gives the same back (no-op), and when providing arguments to FunctionalTranspiler functions in your example in the docs they are plain strings (e.g. [[ hasFeatureFlag(newDashboards, has flag, missing flag) ]]). Furthermore it does not need fixing any existing tests.

I'd gladly elaborate more if you want to discuss it through, but I tried to keep my use case short. ;) Thks @shaharkazaz .

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