2.0.3 • Published 6 months ago

atlas-intl-1 v2.0.3

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
6 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

6 months ago

2.0.2

6 months ago

2.0.1

6 months ago

2.0.0

6 months ago

1.0.107

6 months ago

1.0.106

6 months ago

1.0.109

6 months ago

1.0.108

6 months ago

1.0.105

6 months ago

1.0.103

6 months ago

1.0.102

6 months ago

1.0.104

6 months ago

1.0.101

6 months ago

1.0.100

6 months ago

1.0.99

6 months ago

1.0.98

7 months ago

1.0.97

7 months ago

1.0.69

7 months ago

1.0.68

7 months ago

1.0.73

7 months ago

1.0.72

7 months ago

1.0.71

7 months ago

1.0.70

7 months ago

1.0.77

7 months ago

1.0.76

7 months ago

1.0.75

7 months ago

1.0.74

7 months ago

1.0.79

7 months ago

1.0.78

7 months ago

1.0.80

7 months ago

1.0.84

7 months ago

1.0.83

7 months ago

1.0.82

7 months ago

1.0.81

7 months ago

1.0.88

7 months ago

1.0.87

7 months ago

1.0.86

7 months ago

1.0.85

7 months ago

1.0.89

7 months ago

1.0.91

7 months ago

1.0.90

7 months ago

1.0.95

7 months ago

1.0.94

7 months ago

1.0.93

7 months ago

1.0.92

7 months ago

1.0.96

7 months ago

1.0.62

7 months ago

1.0.61

7 months ago

1.0.60

7 months ago

1.0.66

7 months ago

1.0.65

7 months ago

1.0.64

7 months ago

1.0.63

7 months ago

1.0.67

7 months ago

1.0.37

7 months ago

1.0.36

7 months ago

1.0.39

7 months ago

1.0.38

7 months ago

1.0.44

7 months ago

1.0.43

7 months ago

1.0.42

7 months ago

1.0.41

7 months ago

1.0.48

7 months ago

1.0.47

7 months ago

1.0.46

7 months ago

1.0.45

7 months ago

1.0.49

7 months ago

1.0.51

7 months ago

1.0.50

7 months ago

1.0.55

7 months ago

1.0.54

7 months ago

1.0.53

7 months ago

1.0.52

7 months ago

1.0.59

7 months ago

1.0.58

7 months ago

1.0.57

7 months ago

1.0.56

7 months ago

1.0.33

7 months ago

1.0.32

7 months ago

1.0.35

7 months ago

1.0.34

7 months ago

1.0.19

8 months ago

1.0.18

8 months ago

1.0.17

8 months ago

1.0.16

8 months ago

1.0.9

8 months ago

1.0.8

8 months ago

1.0.7

8 months ago

1.0.6

8 months ago

1.0.22

8 months ago

1.0.21

8 months ago

1.0.20

8 months ago

1.0.26

8 months ago

1.0.25

8 months ago

1.0.24

8 months ago

1.0.23

8 months ago

1.0.29

8 months ago

1.0.28

8 months ago

1.0.27

8 months ago

1.0.11

8 months ago

1.0.10

8 months ago

1.0.31

8 months ago

1.0.30

8 months ago

1.0.15

8 months ago

1.0.14

8 months ago

1.0.13

8 months ago

1.0.12

8 months ago

1.0.5

8 months ago

1.0.4

8 months ago

1.0.3

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago