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

Consistent localized formatting #4268

Conversation

mary-ext
Copy link
Contributor

@mary-ext mary-ext commented May 29, 2024

Just realized Lingui offers convenience methods for language-aware number and date-time formatting via i18n.number() and i18n.date() respectively.

This pull request switches most of our formatting to use that, except for the ago function, I'll touch on that in a separate pull request (haven't figured out how to make unit formatting for months and minutes to not be the same m suffix, I think we might need a separate logic for English, unfortunately)

This seems like the better approach because currently we're very inconsistent as to how we're dealing with localized formatting. Here's how we've been doing it so far:

  • pass undefined as the locale
  • pass locale retrieved from expo-localization
  • pass locale from our content language settings
  • enforce en-US locale

I've removed the formatCountShortOnly function as it's only used in the drawer, I'm not sure why it should be using a different formatting than the one in <Metrics> component, but we can add that back if necessary.

quiple added a commit to quiple/social-app that referenced this pull request May 30, 2024
@mary-ext
Copy link
Contributor Author

mary-ext commented May 30, 2024

I've just noticed that some locales doesn't seem to have any compact notation formatting for thousands specifically, like German and Italian, I'm not sure what to do in this case, should we do a fallback to English in those scenarios? or should we just let it be?

English German
image image

Comment on lines 56 to 60
<Text style={[a.font_bold, t.atoms.text, a.text_md]}>
{formatCount(profile.postsCount || 0)}{' '}
{formatCount(i18n, profile.postsCount || 0)}{' '}
<Text style={[t.atoms.text_contrast_medium, a.font_normal, a.text_md]}>
{plural(profile.postsCount || 0, {one: 'post', other: 'posts'})}
</Text>
Copy link
Contributor Author

@mary-ext mary-ext May 30, 2024

Choose a reason for hiding this comment

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

I feel like there's a better way to do this (where we have different styling for count and suffix) in a way that's more i18n-friendly (doesn't assume spacing and prefix/suffix)

{count, plural,
  one {# <0>post</0>}
  other {# <0>posts</0>}
}

Problem is, I don't understand ICU MessageFormat enough to know if there's like, a way to actually format the number. Perhaps this works as an alternative?

{count, plural,
  one {{fixedCount} <0>post</0>}
  other {{fixedCount} <0>posts</0>}
}

This isn't much of a priority right now though, just food for thought.

@tkusano
Copy link
Contributor

tkusano commented May 30, 2024

In Japanese, i18n.number() defines an compact notation for numbers in tens of thousands, but does not seem to define for numbers in thousands. I think it's fine to leave it as it is, without falling back to English.

@mary-ext mary-ext closed this by deleting the head repository Feb 2, 2025
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