Add joinSentences() to join using sentenceSeparator #1266
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.
This PR adds a function named
joinSentences()
to join two separately translated sentences. In English, there should be a space between the two sentences, but in Japanese and Chinese, there shouldn't be. Often when there are multiple sentences, they are included in the same i18n message. In that case,joinSentences()
isn't needed. It's only useful when combining separate messages.Components already have an alternative to
joinSentences()
in theSentenceSeparator
component. They also have access to thesentenceSeparator
computed ref via theuseI18nUtils()
composable. However, we need a way for non-component code to do something similar. I also thinkjoinSentences()
may be useful even in component code in certain situations.I've added two versions of
joinSentences()
. One is returned byuseI18nUtils()
with the rest of our i18n utility functions. The other can be used outside component code and doesn't need the composable. The one returned byuseI18nUtils()
doesn't need to be passedi18n
because it knows it automatically. I think we may want to follow a similar pattern for our other i18n utility functions: return one version fromuseI18nUtils()
that doesn't requirei18n
(this is what we do today), but then make another version available that does takei18n
and can be used outside component code.The primary motivation for this change is getodk/central#1030. There are some new toast messages where we want to be able to join separately translated sentences.
What has been done to verify that this works as intended?
New tests.
Before submitting this PR, please make sure you have:
npm run test
andnpm run lint
and confirmed all checks still pass OR confirm CircleCI build passes