2.0.3 • Published 7 months ago

atlas-intl-1 v2.0.3

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

7 months ago

2.0.2

7 months ago

2.0.1

7 months ago

2.0.0

7 months ago

1.0.107

7 months ago

1.0.106

7 months ago

1.0.109

7 months ago

1.0.108

7 months ago

1.0.105

7 months ago

1.0.103

7 months ago

1.0.102

7 months ago

1.0.104

7 months ago

1.0.101

7 months ago

1.0.100

7 months ago

1.0.99

7 months ago

1.0.98

7 months ago

1.0.97

7 months ago

1.0.69

8 months ago

1.0.68

8 months ago

1.0.73

8 months ago

1.0.72

8 months ago

1.0.71

8 months ago

1.0.70

8 months ago

1.0.77

8 months ago

1.0.76

8 months ago

1.0.75

8 months ago

1.0.74

8 months ago

1.0.79

8 months ago

1.0.78

8 months ago

1.0.80

8 months ago

1.0.84

8 months ago

1.0.83

8 months ago

1.0.82

8 months ago

1.0.81

8 months ago

1.0.88

8 months ago

1.0.87

8 months ago

1.0.86

8 months ago

1.0.85

8 months ago

1.0.89

8 months ago

1.0.91

8 months ago

1.0.90

8 months ago

1.0.95

8 months ago

1.0.94

8 months ago

1.0.93

8 months ago

1.0.92

8 months ago

1.0.96

8 months ago

1.0.62

8 months ago

1.0.61

8 months ago

1.0.60

8 months ago

1.0.66

8 months ago

1.0.65

8 months ago

1.0.64

8 months ago

1.0.63

8 months ago

1.0.67

8 months ago

1.0.37

8 months ago

1.0.36

8 months ago

1.0.39

8 months ago

1.0.38

8 months ago

1.0.44

8 months ago

1.0.43

8 months ago

1.0.42

8 months ago

1.0.41

8 months ago

1.0.48

8 months ago

1.0.47

8 months ago

1.0.46

8 months ago

1.0.45

8 months ago

1.0.49

8 months ago

1.0.51

8 months ago

1.0.50

8 months ago

1.0.55

8 months ago

1.0.54

8 months ago

1.0.53

8 months ago

1.0.52

8 months ago

1.0.59

8 months ago

1.0.58

8 months ago

1.0.57

8 months ago

1.0.56

8 months ago

1.0.33

8 months ago

1.0.32

8 months ago

1.0.35

8 months ago

1.0.34

8 months ago

1.0.19

9 months ago

1.0.18

9 months ago

1.0.17

9 months ago

1.0.16

9 months ago

1.0.9

9 months ago

1.0.8

9 months ago

1.0.7

9 months ago

1.0.6

9 months ago

1.0.22

9 months ago

1.0.21

9 months ago

1.0.20

9 months ago

1.0.26

9 months ago

1.0.25

9 months ago

1.0.24

9 months ago

1.0.23

9 months ago

1.0.29

9 months ago

1.0.28

9 months ago

1.0.27

9 months ago

1.0.11

9 months ago

1.0.10

9 months ago

1.0.31

9 months ago

1.0.30

9 months ago

1.0.15

9 months ago

1.0.14

9 months ago

1.0.13

9 months ago

1.0.12

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago