Skip to content

feat(transloco): transpile function arguments in FunctionalTranspiler (#829)#832

Merged
shaharkazaz merged 4 commits intojsverse:masterfrom
f-aubert:transloco-functionaltranspiler
Apr 17, 2026
Merged

feat(transloco): transpile function arguments in FunctionalTranspiler (#829)#832
shaharkazaz merged 4 commits intojsverse:masterfrom
f-aubert:transloco-functionaltranspiler

Conversation

@f-aubert
Copy link
Copy Markdown
Contributor

@f-aubert f-aubert commented Jan 15, 2025

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • [X ] Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: 829

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • [X ] No

Other information

Summary by CodeRabbit

  • Bug Fixes

    • Fixed translation function handling to properly transpile and resolve interpolated values within function arguments before passing them to the function processor.
  • Tests

    • Added test cases verifying that function calls with interpolated placeholder arguments (including nested properties) are correctly transpiled and resolved.

…jsverse#829)

Signed-off-by: isc-auf <frederic.aubert@isc-ejpd.admin.ch>
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jan 15, 2025

Open in StackBlitz

@jsverse/transloco

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco@832

@jsverse/transloco-locale

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-locale@832

@jsverse/transloco-messageformat

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-messageformat@832

@jsverse/transloco-optimize

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-optimize@832

@jsverse/transloco-persist-lang

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-persist-lang@832

@jsverse/transloco-persist-translations

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-persist-translations@832

@jsverse/transloco-preload-langs

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-preload-langs@832

@jsverse/transloco-schematics

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-schematics@832

@jsverse/transloco-scoped-libs

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-scoped-libs@832

@jsverse/transloco-utils

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-utils@832

@jsverse/transloco-validator

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-validator@832

commit: 086e8f2

@f-aubert
Copy link
Copy Markdown
Contributor Author

@shaharkazaz ? May I assist you in letting this merged? thxs

@shaharkazaz
Copy link
Copy Markdown
Collaborator

@f-aubert See my comment

Comment on lines +184 to +187
return func.transpile(...getFunctionArgs(args));
return func.transpile(
...getFunctionArgs(args).map((arg) =>
this.transpile({ value: arg, ...rest }),
),
Copy link
Copy Markdown
Collaborator

@shaharkazaz shaharkazaz Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question here do we want to support nested function transpilations? I'm not sure that would actually work.
Add a test case, if that works, cool. otherwise let's skip directly to the parent transpiler

const transpiledArgs = super.transpile({value: getFunctionArgs(args), ...rest});
return func.transpile(...transpiledArgs);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. As far as I can tell, this PR doesn't implements nesting function because getFunctionArgs use a simple pattern to separate the args, namely on comma. A regexp engine with support of nesting would be needed. I sure can look into that, but I could also live with this limitation.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep it simple

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the changes and test the pkg-pr-new release

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exactly sure what do you want me to do / change? I think the original code with the map call should do it... Thks

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please call the super like in the code I suggested

@f-aubert f-aubert force-pushed the transloco-functionaltranspiler branch from 5597e5d to ec8ff1c Compare August 11, 2025 12:49
@f-aubert
Copy link
Copy Markdown
Contributor Author

I pushed what you suggested. I called this.transpile (instead of super.transpile) on the functionArgs. It shouldn't have any impact, but would allow nesting function if we ever improved the parsing in getFunctionArgs (to ignore coma when in a nested context such as [[ or {{).
Git Technic: I did merge your master branch in my transloco-functional-transpiler fork. I hope it suits you, else I can always start again and create a new branch with just one commit with my changes.

@f-aubert
Copy link
Copy Markdown
Contributor Author

Hello @shaharkazaz would you agree to go forwards? I'd enjoy this or a new similar pr merged

@f-aubert
Copy link
Copy Markdown
Contributor Author

Hello @shaharkazaz? Can we imagine merging it? Thks

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 17, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

Updated the FunctionalTranspiler to recursively transpile parsed argument lists before passing them to functions, enabling proper handling of interpolation-backed parameters in function calls. Added a corresponding test case verifying the new argument transpilation behavior.

Changes

Cohort / File(s) Summary
Transpiler Argument Handling
libs/transloco/src/lib/transloco.transpiler.ts, libs/transloco/src/lib/tests/transpiler.spec.ts
Updated FunctionalTranspiler.transpile to recursively transpile parsed argument lists before passing them to functions. Added test case verifying function-call arguments with interpolation placeholders (including nested property access) are properly resolved before invocation.

Fun fact: Did you know that some languages have different plural forms depending on the number? For example, in Polish, the word "kotów" (cats) has multiple plural forms depending on whether you're talking about 2-4 cats, 5+ cats, or just 1 cat. This is why robust i18n systems like Transloco must support complex pluralization rules beyond the simple singular/plural distinction!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: transpiling function arguments in FunctionalTranspiler, directly matching the code modifications in the PR.
Description check ✅ Passed The PR description follows the template structure with all required sections completed: checklist items marked, PR type selected as Feature, issue number provided, and breaking change status indicated.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@shaharkazaz shaharkazaz merged commit da35543 into jsverse:master Apr 17, 2026
7 of 8 checks passed
@f-aubert
Copy link
Copy Markdown
Contributor Author

@shaharkazaz wow! great didn't expect it now, nice gift. Thanks for your work.

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

Successfully merging this pull request may close these issues.

2 participants