# useTranslate
Returns the `I18nTranslate` interface used to translate strings.
```jsx
/* See the locales/en.default.json tab for the translation keys and values for this example */
import {
reactExtension,
Text,
useTranslate,
} from '@shopify/ui-extensions-react/checkout';
export default reactExtension(
'purchase.checkout.block.render',
() => ,
);
function Extension() {
const translate = useTranslate();
return (
{translate('welcomeMessage')}
);
}
```
```json
{
"welcomeMessage": "Welcome to our store!"
}
```
##
### UseTranslateGeneratedType
Returns the `I18nTranslate` interface used to translate strings.
#### Returns: I18nTranslate
export function useTranslate<
Target extends RenderExtensionTarget = RenderExtensionTarget,
>(): I18nTranslate {
const {i18n} = useApi();
const translate = useCallback(
(...args) => {
const translation = i18n.translate(...args);
if (!Array.isArray(translation)) {
return translation as any;
}
return translation.map((part, index) => {
if (isValidElement(part)) {
// eslint-disable-next-line react/no-array-index-key
return cloneElement(part as RemoteComponentType, {key: index});
}
return part;
});
},
[i18n],
);
return translate;
}
## Related
- [StandardApi](https://shopify.dev/docs/api/checkout-ui-extensions/apis/standardapi)
- [CheckoutApi](https://shopify.dev/docs/api/checkout-ui-extensions/apis/checkoutapi)
- [OrderStatusApi](https://shopify.dev/docs/api/checkout-ui-extensions/apis/orderstatusapi)
- [CartLineItemApi](https://shopify.dev/docs/api/checkout-ui-extensions/apis/cartlineitemapi)
- [PickupPointListApi](https://shopify.dev/docs/api/checkout-ui-extensions/apis/pickuppointlistapi)
- [PickupLocationListApi](https://shopify.dev/docs/api/checkout-ui-extensions/apis/pickuplocationlistapi)
- [ShippingOptionItemApi](https://shopify.dev/docs/api/checkout-ui-extensions/apis/shippingoptionitemapi)
- [ExtensionTargets](https://shopify.dev/docs/api/checkout-ui-extensions/apis/extensiontargets)
## Examples
Returns the `I18nTranslate` interface used to translate strings.
You can use the `count` option to get a pluralized string based on the current locale.
See [localizing UI extensions](https://shopify.dev/docs/apps/checkout/best-practices/localizing-ui-extensions) for more information.
```jsx
/* See the locales/en.default.json tab for the translation keys and values for this example */
import {
reactExtension,
Banner,
useApi,
useTranslate,
} from '@shopify/ui-extensions-react/checkout';
export default reactExtension(
'purchase.checkout.block.render',
() => ,
);
function Extension() {
const {i18n} = useApi();
const translate = useTranslate();
const points = 10000;
const formattedPoints =
i18n.formatNumber(points);
// Translate the loyalty points message, using pluralization to differentiate messages
const loyaltyPointsMsg = translate(
'loyaltyPoints',
{
count: points,
formattedPoints,
},
);
return ;
}
```
```json
{
"loyaltyPoints": {
"one": "You have {{formattedPoints}} loyalty point",
"other": "You have {{formattedPoints}} loyalty points"
}
}
```
## Examples
Returns the `I18nTranslate` interface used to translate strings.
You can use the `count` option to get a pluralized string based on the current locale.
See [localizing UI extensions](https://shopify.dev/docs/apps/checkout/best-practices/localizing-ui-extensions) for more information.
```jsx
/* See the locales/en.default.json tab for the translation keys and values for this example */
import {
reactExtension,
Banner,
useApi,
useTranslate,
} from '@shopify/ui-extensions-react/checkout';
export default reactExtension(
'purchase.checkout.block.render',
() => ,
);
function Extension() {
const {i18n} = useApi();
const translate = useTranslate();
const points = 10000;
const formattedPoints =
i18n.formatNumber(points);
// Translate the loyalty points message, using pluralization to differentiate messages
const loyaltyPointsMsg = translate(
'loyaltyPoints',
{
count: points,
formattedPoints,
},
);
return ;
}
```
```json
{
"loyaltyPoints": {
"one": "You have {{formattedPoints}} loyalty point",
"other": "You have {{formattedPoints}} loyalty points"
}
}
```