Repository navigation
Add formatParams to format placeholder values before t - #3
Merged
Merged
Conversation
✅ Incremental coverage — 100%
6 files not graded (2 ignored by pattern, 4 not source files)
Coverage reports: coverage/coverage-final.json (istanbul, 1 file) — incremental-coverage-check v3.0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
formatParams(t, format)returns a translation function that passes each placeholder value throughformatbeforetsubstitutes it. vue-i18n'stsubstitutes a value asString(value), so numbers miss the locale's digits and separators and dates print asDate.prototype.toString. WithformatParams(t, v => typeof v === 'number' ? n(v) : v instanceof Date ? d(v) : v)the application formats values once, for every library, and the package still does not depend on vue-i18n.formatreads (vue-i18n's locale throughn/d) is tracked by the computed or render that reads the string.namedis not mutated; the result oftis returned unchanged, so a returned key still means no translation.translateis unchanged and interpolates unformatted values.Tests (real vue-i18n): Persian digits with
ninfa, a date withd, an unchanged value, no mutation, a getter read per call, a locale switch fa → en inside a computed, reactivity of state read only byformat(over a non-reactivet), the unformatted English fallback, andformatParamsover aninterpolate-basedtwithIntl.readme:
formatParamsin the intro, the valuesnamedholds, new section Formatting values in the application part, two vue-i18n notes. changelog and version 0.3.0.