feat: support formatting function with plural and interpolation #2325
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Close #2323 .
Checklist
npm run test
Feature
Use formatting functions with interpolation and plurals in the nesting "$t" function.
Example:
Note: you should not put formatters before the nesting option object. Because this is not only illogical, but also increases the complexity of the code. For example, the following code will not work properly.
Additional Info
doReduce
i18next/src/Interpolator.js
Line 281 in a7f7d06
i18next/src/Interpolator.js
Line 301 in a7f7d06
Here is a variable
doReduce
, but I don't understand what it does, so I replaced it withformatters.length
.nestingRegexp
I found that the part that determines the
$t()
function currently uses a simple regular expression to match. Ignoring custom configuration, its default value is/\$t\((.+?)\)/
. This means that if you include a right parenthesis inside the function, it will break the function from working properly. For example:This will break the function. However, since this part is beyond the scope of the target issue, I will not fixed it yet. I'm just giving a heads up.