Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Locale changes #1650

Merged
merged 6 commits into from
Feb 23, 2024
Merged

Locale changes #1650

merged 6 commits into from
Feb 23, 2024

Conversation

mnvr
Copy link
Member

@mnvr mnvr commented Feb 23, 2024

The code has been refactored to the way I wanted. The final step is to actually switch over from storing language codes to storing the full locale so that we can handle e.g. pt-BR. That'll be in a subsequent PR.

mnvr added 6 commits February 22, 2024 22:54
It is indeed possible to have a TypeScript type and an array of all of its
possible values without repeating ourselves.

The trick is - while we cannot go from types to values, we can go the other way
around. The sidetrick is - typeof array[number] gives us type of an array's
elements.

Combined, we get this pattern

    const fruits = ["banana", "orange"] as const;
    type Fruits = (typeof fruits)[number];

Refs:
- https://stackoverflow.com/questions/53154564/how-to-get-all-possible-values-of-a-union-type-to-an-array-or-the-other-way-aro
- https://www.typescriptlang.org/docs/handbook/2/indexed-access-types.html
Copy link

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1b6f020
Status: ✅  Deploy successful!
Preview URL: https://7fd0990d.bada-frame.pages.dev
Branch Preview URL: https://locale.bada-frame.pages.dev

View logs

@mnvr mnvr merged commit 372a9c9 into main Feb 23, 2024
5 checks passed
@mnvr mnvr deleted the locale branch February 23, 2024 05:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant