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

✨ i18n support #2356

Closed
wants to merge 4 commits into from
Closed

✨ i18n support #2356

wants to merge 4 commits into from

Conversation

KenAJoh
Copy link
Collaborator

@KenAJoh KenAJoh commented Oct 7, 2023

Description

Resolves #2334

POC/WIP for i18n support

Hvordan fungerer det?

  1. Aksel tilbyr pre-configs for diverse språk i /locales/*.json
  2. Alle komponenter bruker som default nb.json gjennom i18n context
  3. Bruker kan velge annet språk gjennom Provider-komponent
import enGB from "@navikt/ds-react/locales/enGB.json";
...
<Provider i18n={enGB}>
...
</Provider>
  1. Bruker kan også legge til eget språk eller bare overskrive deler av config. Key-value pairs som mangler vil bli merget inn slik at man får en fullverdig i18n config. (Bør man ha nb som default fallback hvis bruker mangler et key-value pair her?)
import enGB from "@navikt/ds-react/locales/enGB.json";
...
const myCustomi18nConfig = {
  key: value
}
<Provider i18n={[myCustomi18nConfig, enGB]}>
...
</Provider>
  1. Bruker kan også overskrive/endre i18n config lokalt på komponentnivå basert på context utenfra. Slipper da å overskrive "globale" verdier basert på lokal context
<Alert translations={{key: "custom value based on context}}>
  1. Translatefunksjon (TODO atm) bruker en regex for translation som kan bytte ut alt mellom {} med input.
// nb.json
{
  "Textarea": {
    "counter": {
      "charactersLeft": "Du har {tegn} tegn igjen"
    }
  }
}
----
<span>{translate("Textarea.counter.charactersLeft", 200)}
---
// Output: Du har 200 tegn igjen

@changeset-bot
Copy link

changeset-bot bot commented Oct 7, 2023

⚠️ No Changeset found

Latest commit: db02f94

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

@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2023

Storybook demo

Endringer til review: 1

4477175d8 | 59 komponenter | 386 stories

@KenAJoh
Copy link
Collaborator Author

KenAJoh commented Feb 5, 2024

Blir implementert og testet lokalt i #2504

@KenAJoh KenAJoh closed this Feb 5, 2024
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.

[NEW] Eksponere labels-prop i Datepicker
2 participants