Skip to content

Commit

Permalink
Remove namespace from i18n example (#434)
Browse files Browse the repository at this point in the history
Actual Budget does not use namespaces in the translations.
Also adds additional section about handling interpolation using the
<Trans> component.
  • Loading branch information
julianwachholz authored Aug 16, 2024
1 parent 6772a1c commit 583dd24
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions docs/contributing/i18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The `t()` function is the simplest form of translation, it accepts the text to b
import { useTranslation } from 'react-i18next';

function MyComponent() {
const { t } = useTranslation('myNamespace');
const { t } = useTranslation();

return <p>{t('Hello World')}</p>;
}
Expand All @@ -61,7 +61,7 @@ i18next will take care of proper pluralization rules in the currently active lan
When translating text with simple HTML tags or other React components, you will need to use the [`<Trans>` component](https://react.i18next.com/latest/trans-component).

```javascript
import { Trans, useTranslation } from 'react-i18next';
import { Trans } from 'react-i18next';

function MyComponent() {
return (
Expand All @@ -71,3 +71,24 @@ function MyComponent() {
);
}
```

#### Interpolation with `<Trans>`

Handling placeholder variables and pluralization within the `<Trans>` React component is handled slightly differently. For more details, please refer to [i18next-react's documentation](https://react.i18next.com/latest/trans-component#interpolation).


```javascript
import { Trans } from 'react-i18next';

function MyComponent() {
const person = { name: "Pedro" };
// You can use an object literal within <Trans>!
return (
<Trans>
Your name is {{ name: person.name }}.
</Trans>
);
// This will result in the translation string:
// "Your name is {{name}}."
}
```

0 comments on commit 583dd24

Please sign in to comment.