2.0.3 • Published 4 months ago

atlas-intl-1 v2.0.3

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
4 months ago

Overview

The atlas-intl repository provides internationalization support for the Atlas application. It leverages Tolgee for translation management and integrates with React applications to enable dynamic translations.

Installation

To add atlas-intl to your project, install it using yarn: yarn add @globalsign/atlas-intl

Basic Implementation

AtlasIntlProvider

Wrap your application with the AtlasIntlProvider component to set up internationalization:

import { AtlasIntlProvider } from '@globalsign/atlas-intl';

const App = () => (
  <AtlasIntlProvider
    language="en-US"
    availableLanguages={['en-US', 'fr-FR']}
    namespaces={['common', 'dashboard']}
    staticTranslations={{
      'en-US': { common: { welcome: 'Welcome!' } },
      'fr-FR': { common: { welcome: 'Bienvenue!' } },
    }}
    prefix="/translations"
  >
    <YourMainComponent />
  </AtlasIntlProvider>
);

Parameters:

language: The default language (e.g., 'en-US'). availableLanguages: An array of supported languages. namespaces: A list of namespaces for grouping translations. staticTranslations: (Optional) Preloaded translations for static data. prefix: (Optional) URL prefix for fetching translations dynamically. Plugins: (Optional) Array of additional Tolgee plugins.

useTranslation

Use the useTranslation hook to access translation functions. This hook accepts a default namespace and returns:

t: A function for translating keys dynamically. T: A React component for translations with support for parameters. Example:

import { useTranslation } from '@globalsign/atlas-intl';

const MyComponent = () => {
  const { t, T } = useTranslation('common');

  return (
    <div>
      <h1>{t('welcome', { name: 'John' }, 'Hello!', 'common')}</h1>
      <T keyName="welcome" params={{ name: 'John' }} />
    </div>
  );
};

FormattedMessage

The FormattedMessage component is used to display localized messages. It supports both string keys and structured message objects.

Structured Message Object:

id: Translation key. defaultMessage: Fallback message if the key is not found. params: A key-value object for dynamic parameters. ns: (Optional) Namespace for the translation key. Example:

import { FormattedMessage } from '@globalsign/atlas-intl';

const messages = {
  testTitle: {
    id: 'test.key',
    defaultMessage: 'Default Value',
    ns: 'testNamespace',
    params: { user: 'Alice' },
  },
};

const MyComponent = () => <FormattedMessage message={messages.testTitle} />;

Customization

Namespaces: Add or modify namespaces as needed in the AtlasIntlProvider which will be pulled when tolgee is initialised:

.init({
ns: ['namespace1', 'namespace2'],
});

Language: Change the default language in the init configuration.

Scripts

Clean: Remove the dist directory: yarn clean

Build: Transpile the source files: yarn build

2.0.3

4 months ago

2.0.2

4 months ago

2.0.1

4 months ago

2.0.0

4 months ago

1.0.107

4 months ago

1.0.106

4 months ago

1.0.109

4 months ago

1.0.108

4 months ago

1.0.105

4 months ago

1.0.103

5 months ago

1.0.102

5 months ago

1.0.104

5 months ago

1.0.101

5 months ago

1.0.100

5 months ago

1.0.99

5 months ago

1.0.98

5 months ago

1.0.97

5 months ago

1.0.69

6 months ago

1.0.68

6 months ago

1.0.73

6 months ago

1.0.72

6 months ago

1.0.71

6 months ago

1.0.70

6 months ago

1.0.77

5 months ago

1.0.76

5 months ago

1.0.75

5 months ago

1.0.74

5 months ago

1.0.79

5 months ago

1.0.78

5 months ago

1.0.80

5 months ago

1.0.84

5 months ago

1.0.83

5 months ago

1.0.82

5 months ago

1.0.81

5 months ago

1.0.88

5 months ago

1.0.87

5 months ago

1.0.86

5 months ago

1.0.85

5 months ago

1.0.89

5 months ago

1.0.91

5 months ago

1.0.90

5 months ago

1.0.95

5 months ago

1.0.94

5 months ago

1.0.93

5 months ago

1.0.92

5 months ago

1.0.96

5 months ago

1.0.62

6 months ago

1.0.61

6 months ago

1.0.60

6 months ago

1.0.66

6 months ago

1.0.65

6 months ago

1.0.64

6 months ago

1.0.63

6 months ago

1.0.67

6 months ago

1.0.37

6 months ago

1.0.36

6 months ago

1.0.39

6 months ago

1.0.38

6 months ago

1.0.44

6 months ago

1.0.43

6 months ago

1.0.42

6 months ago

1.0.41

6 months ago

1.0.48

6 months ago

1.0.47

6 months ago

1.0.46

6 months ago

1.0.45

6 months ago

1.0.49

6 months ago

1.0.51

6 months ago

1.0.50

6 months ago

1.0.55

6 months ago

1.0.54

6 months ago

1.0.53

6 months ago

1.0.52

6 months ago

1.0.59

6 months ago

1.0.58

6 months ago

1.0.57

6 months ago

1.0.56

6 months ago

1.0.33

6 months ago

1.0.32

6 months ago

1.0.35

6 months ago

1.0.34

6 months ago

1.0.19

6 months ago

1.0.18

6 months ago

1.0.17

6 months ago

1.0.16

6 months ago

1.0.9

7 months ago

1.0.8

7 months ago

1.0.7

7 months ago

1.0.6

7 months ago

1.0.22

6 months ago

1.0.21

6 months ago

1.0.20

6 months ago

1.0.26

6 months ago

1.0.25

6 months ago

1.0.24

6 months ago

1.0.23

6 months ago

1.0.29

6 months ago

1.0.28

6 months ago

1.0.27

6 months ago

1.0.11

7 months ago

1.0.10

7 months ago

1.0.31

6 months ago

1.0.30

6 months ago

1.0.15

6 months ago

1.0.14

6 months ago

1.0.13

6 months ago

1.0.12

7 months ago

1.0.5

7 months ago

1.0.4

7 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago