Lingui is an internationalization framework for JavaScript. This skill provides best practices for using i18n in React and vanilla JavaScript applications.
$ npx skills add https://github.com/lingui/skills --skill lingui-best-practicesLingui Best Practices provides a structured approach to adding i18n to React and vanilla JavaScript applications. The skill covers the complete Lingui workflow: wrapping apps with I18nProvider, marking messages with macros (Trans, useLingui, Plural), extracting messages via CLI, translating catalogs, and compiling locales. It includes patterns for handling JSX content, string attributes, lazy translations, pluralization with exact number matching, and locale-aware date/number formatting using the Intl API. Developers learn when to use Trans for JSX, useLingui for non-JSX strings, and msg for module-level constants, plus configuration setup and ESLint plugin integration to prevent common mistakes.
Install using the command: `$ npx skills add https://github.com/lingui/skills --skill lingui-best-practices`
Implementing internationalization in React apps
Marking messages for translation
Extracting and compiling translation catalogs
$ npx skills add https://github.com/lingui/skills --skill lingui-best-practicesgit clone https://github.com/lingui/skillsCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
Provide best practices for implementing internationalization (i18n) using Lingui in a [PROJECT_TYPE] application (React or vanilla JavaScript). Focus on [SPECIFIC_AREA: e.g., dynamic messages, pluralization, context, or performance optimization]. Include code snippets where relevant.
# Lingui Best Practices for React Applications
## 1. Project Structure
Organize your i18n files logically:
```
/src/
/locales/
/en/
messages.js
/fr/
messages.js
/components/
Button/
Button.jsx
Button.i18n.js
```
## 2. Dynamic Messages with Variables
Use ICU MessageFormat syntax for dynamic content:
```jsx
// Button.i18n.js
export const messages = {
greeting: 'Hello {name}!',
items_count: '{count, plural, one {1 item} other {{count} items}}'
};
// Button.jsx
import { t } from '@lingui/macro';
const Button = ({ name, count }) => (
<button>
{t`Hello ${name}!`}
{t`You have ${count} items`}
</button>
);
```
## 3. Context for Disambiguation
Add context when messages have multiple meanings:
```jsx
// In your message catalog:
{ 'message': 'Bank' }
{ 'message@financial': 'Financial institution' }
{ 'message@river': 'Side of a river' }
// Usage:
t`message` // -> 'Bank'
t`message@financial` // -> 'Financial institution'
```
## 4. Performance Optimization
- Use `@lingui/macro` for compile-time extraction
- Mark static messages with `/*i18n-disable*/` when needed
- Avoid inline message definitions in render methods:
❌ Bad: `t('Hello {name}', { name })`
✅ Good: Extract to message catalog first
## 5. Testing Strategy
```javascript
import { i18n } from '@lingui/core';
import { setupI18n } from '@lingui/react';
test('renders localized content', () => {
const i18n = setupI18n({ locale: 'en', messages: { en: {} } });
render(<Component />, { wrapper: ({ children }) => <I18nProvider i18n={i18n}>{children}</I18nProvider> });
expect(screen.getByText(/hello/i)).toBeInTheDocument();
});
```
## Key Takeaways
- Centralize message definitions in catalog files
- Use ICU syntax for complex messages
- Implement context when needed
- Optimize performance with macros and proper structure
- Test with mocked i18n providersTake a free 3-minute scan and get personalized AI skill recommendations.
Take free scan