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

feat: Introduce a number locale override #34

Merged
merged 7 commits into from
Nov 5, 2024

Conversation

DanielWilliamClarke
Copy link
Contributor

@DanielWilliamClarke DanielWilliamClarke commented Nov 4, 2024

Description

We need to be able to format numbers on the AT point of sale like we do in DE

This is handed by Intl.NumberFormat(locale, value) in Phrasebook

We pass de-AT as the locale on the AT pos, where we expect numbers to be formatted like 12.345 but instead we see 12 345. This is because Intl.NumberFormat() doesn't really recognise de-AT and just falls back to a default

To handle this, and render numbers in AT like they are shown in DE, I propose here to pass through the t() method an override locale, the reasons for this are

  • Passing a preformatted stringified count value will shut of the inbuilt pluralisation functionality, and would require a fair amount of logic to parse these values back to numbers to regain it, considering that DE formatted numbers like decimals to the outside world this is a bit tricky 1.234 -> 1 etc
  • We already have a secondary locale in place in sunrise that can be configured via Sanity so passing this value on a need to use basis is rather simple by the consumer

Expected usage in consumers

const { t } = useTranslation();
const {
  site: { secondaryLocale },
} = useAppContext();

... 
t('xHolidaysFound', { count, overrideLocale: secondaryLocale })

For these reasons the proposed changes in this PR yield the simplest way forward

Copy link

changeset-bot bot commented Nov 4, 2024

⚠️ No Changeset found

Latest commit: 358d49e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

github-actions bot commented Nov 4, 2024

Size Change: +26 B (+2.34%)

Total Size: 1.14 kB

Filename Size Change
./lib/index.js 1.14 kB +26 B (+2.34%)

compressed-size-action

@DanielWilliamClarke DanielWilliamClarke merged commit c33cc3c into main Nov 5, 2024
1 check passed
@DanielWilliamClarke DanielWilliamClarke deleted the introduce-number-local-override branch November 5, 2024 09:52
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.

3 participants