2.0.3 • Published 1 year ago

atlas-intl-1 v2.0.3

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

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.0.107

1 year ago

1.0.106

1 year ago

1.0.109

1 year ago

1.0.108

1 year ago

1.0.105

1 year ago

1.0.103

1 year ago

1.0.102

1 year ago

1.0.104

1 year ago

1.0.101

1 year ago

1.0.100

1 year ago

1.0.99

1 year ago

1.0.98

1 year ago

1.0.97

1 year ago

1.0.69

1 year ago

1.0.68

1 year ago

1.0.73

1 year ago

1.0.72

1 year ago

1.0.71

1 year ago

1.0.70

1 year ago

1.0.77

1 year ago

1.0.76

1 year ago

1.0.75

1 year ago

1.0.74

1 year ago

1.0.79

1 year ago

1.0.78

1 year ago

1.0.80

1 year ago

1.0.84

1 year ago

1.0.83

1 year ago

1.0.82

1 year ago

1.0.81

1 year ago

1.0.88

1 year ago

1.0.87

1 year ago

1.0.86

1 year ago

1.0.85

1 year ago

1.0.89

1 year ago

1.0.91

1 year ago

1.0.90

1 year ago

1.0.95

1 year ago

1.0.94

1 year ago

1.0.93

1 year ago

1.0.92

1 year ago

1.0.96

1 year ago

1.0.62

1 year ago

1.0.61

1 year ago

1.0.60

1 year ago

1.0.66

1 year ago

1.0.65

1 year ago

1.0.64

1 year ago

1.0.63

1 year ago

1.0.67

1 year ago

1.0.37

1 year ago

1.0.36

1 year ago

1.0.39

1 year ago

1.0.38

1 year ago

1.0.44

1 year ago

1.0.43

1 year ago

1.0.42

1 year ago

1.0.41

1 year ago

1.0.48

1 year ago

1.0.47

1 year ago

1.0.46

1 year ago

1.0.45

1 year ago

1.0.49

1 year ago

1.0.51

1 year ago

1.0.50

1 year ago

1.0.55

1 year ago

1.0.54

1 year ago

1.0.53

1 year ago

1.0.52

1 year ago

1.0.59

1 year ago

1.0.58

1 year ago

1.0.57

1 year ago

1.0.56

1 year ago

1.0.33

1 year ago

1.0.32

1 year ago

1.0.35

1 year ago

1.0.34

1 year ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.22

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.26

1 year ago

1.0.25

1 year ago

1.0.24

1 year ago

1.0.23

1 year ago

1.0.29

1 year ago

1.0.28

1 year ago

1.0.27

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.31

1 year ago

1.0.30

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago