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 Internationalization starter setup #190

Merged
merged 1 commit into from
Jul 31, 2024

Conversation

adamjarling
Copy link
Collaborator

What does this do?

Implements some initial i18n patterns for how to define and use internationalization in Clover. This approach uses the React flavor of the i18Next package.

Directory structure

/src/i18n

  • config.ts - Root config file
  • /@types - Support for Typescript
  • [language here] - i.e. en, de, etc.
    • Individual .json files can live here, which name space the different Clover exports? i.e. viewer.json, common.json, bloom.json, etc...

How it works

Pull in the configuration by importing confg.ts into a top level file.

// src/components/Viewer/index.tsx

import "src/i18n/config";

Then use translations in a component like so:

import { useTranslation } from "react-i18next";

export default MyComponent() {
  // Pass in an optional array of namespaces to use short-hand references
  const { t } = useTranslation(["viewer"]);

  return (
    <>
      <span>{ t("aside.collapsibleTrigger.openMessage") }(</span>

      {/* Or alternatively target the namespace */}
       <span>{ t("viewer:aside.collapsibleTrigger.openMessage") }(</span>
    </>
  )

}

Notes

To enable Typescript support (type checking and autocomplete), this file will have to be accurate, and stay in sync with the directory structures:

src/i18n/@types/resources.ts

Currently en is configured to be the default, but as i18n becomes more populated there is an LanguageDetector we can eventually pull into initial configuration.

// src/i18n/config.ts

import LanguageDetector from 'i18next-browser-languagedetector';

i18next
  .use(LanguageDetector)
  .use(initReactI18next).init({...})

@adamjarling adamjarling self-assigned this Mar 25, 2024
@mathewjordan mathewjordan self-requested a review April 5, 2024 16:22
@adamjarling adamjarling force-pushed the 173-i18n-internationalization branch from ee411db to afa0a27 Compare July 19, 2024 18:15
@mathewjordan mathewjordan force-pushed the 173-i18n-internationalization branch 2 times, most recently from faac4fd to 29006b3 Compare July 31, 2024 17:57
@mathewjordan mathewjordan force-pushed the 173-i18n-internationalization branch from 29006b3 to 4ff4279 Compare July 31, 2024 18:18
@mathewjordan mathewjordan merged commit 7e71769 into main Jul 31, 2024
1 check passed
@mathewjordan mathewjordan deleted the 173-i18n-internationalization branch July 31, 2024 18:19
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