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

Component for i18n punctuation and spacing #650

Closed
matthew-white opened this issue Nov 16, 2022 · 2 comments
Closed

Component for i18n punctuation and spacing #650

matthew-white opened this issue Nov 16, 2022 · 2 comments
Assignees
Labels
i18n Internationalization refactor Improves code without altering behavior

Comments

@matthew-white
Copy link
Member

The <sentence-separator> component is used when a space character is needed within or between text, but only in some locales. (Currently, Japanese is the only locale for which <sentence-separator> doesn't render a space character.) Historically, we've only used <sentence-separator> for the space between sentences (hence the name), but as of #641, we now use it more expansively for any locale-conditional space character. See #641 (comment). This issue is to rename <sentence-separator> to encompass that broader use. I was thinking of the name <i18n-space>.

@matthew-white matthew-white added help wanted good first issue refactor Improves code without altering behavior i18n Internationalization and removed help wanted good first issue labels Nov 16, 2022
@matthew-white
Copy link
Member Author

Hmm I wonder if we should make this component even more expansive. Maybe we should name it <i18n-punc> and have it manage all punctuation/spacing as it relates to i18n. As of #641, we now support i18n commas, and we do something similar on a more ad-hoc basis with parentheses. We could bundle all that together in a single component.

@matthew-white matthew-white changed the title Rename <sentence-separator> to <i18n-space> Component for i18n punctuation and spacing Nov 16, 2022
@matthew-white matthew-white self-assigned this Apr 19, 2024
@github-project-automation github-project-automation bot moved this to 🕒 backlog in ODK Central Apr 19, 2024
@matthew-white matthew-white moved this from 🕒 backlog to ✏️ in progress in ODK Central Apr 19, 2024
@matthew-white
Copy link
Member Author

matthew-white commented Apr 19, 2024

This has come up for the entity upload modal (getodk/central#589 and getodk/central#593). The new Pagination component shows ranges of numbers, but different locales write ranges differently. For example, in Japanese, a range looks like 100~200 rather than 100–200. We also have one more comma-separated list in the EntityUploadWarnings component.

I'm taking a different approach from before, making greater use of Intl. For example, we can format a list using Intl.ListFormat, which handles all list-related formatting, including whether there are spaces between text. I like using Intl because it allows us to make fewer assumptions about how the punctuation works, and because it doesn't require translators to translate punctuation. I've created a component <i18n-list>, which parallels Vue I18n's <i18n-n>: just as <i18n-n> uses Intl.NumberFormat.prototype.formatToParts() under the hood, <i18n-list> uses Intl.ListFormat.prototype.formatToParts(). I haven't needed to add a component for ranges yet, just a utility function: the useI18nUtils() composable now returns a formatRange() function.

There may be other punctuation in the future, including punctuation not handled by Intl. That means that we may see more components and/or utility functions in the future. However, given that punctuation so far has been handled specifically rather than generally, I don't think it's likely that we'll want a generic component like <i18n-punc> described above. Also, now that <i18n-list> does some handling of space between text, <sentence-separator> is once again just used for sentence separation. I don't think we need to rename it to <i18n-space>.

matthew-white added a commit that referenced this issue Apr 19, 2024
matthew-white added a commit that referenced this issue Apr 25, 2024
@github-project-automation github-project-automation bot moved this from ✏️ in progress to ✅ done in ODK Central Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
i18n Internationalization refactor Improves code without altering behavior
Projects
Status: ✅ done
Development

No branches or pull requests

1 participant