From 3e9c45f3d9cc6b8ca3471357eef8fc28d814b275 Mon Sep 17 00:00:00 2001 From: Vojtech Novak Date: Sun, 23 Apr 2023 17:46:21 +0200 Subject: [PATCH] docs: more updates --- website/docs/ref/macro.md | 4 ++- website/docs/tutorials/react-native.md | 45 ++++++++++++-------------- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/website/docs/ref/macro.md b/website/docs/ref/macro.md index 5785471cc..6d38e9a52 100644 --- a/website/docs/ref/macro.md +++ b/website/docs/ref/macro.md @@ -609,7 +609,9 @@ const message = t({ ### `defineMessage` alias: `msg` {#definemessage} -`defineMessage` macro allows to define message for later use. It has the same signature as `t` macro, but unlike it, it doesn't wrap generated *MessageDescription* into [`i18n._`](/docs/ref/core.md#i18n._) call. +`defineMessage` macro allows to define message for later use. It returns a `MessageDescriptor` that you can pass to `i18n._` to get a translated string at any time later. + +In another words, `t` returns a translated string at the time when it's called, while `msg` returns a ``MessageDescriptor` that can produce translated strings later. ```ts import { defineMessage } from "@lingui/macro" diff --git a/website/docs/tutorials/react-native.md b/website/docs/tutorials/react-native.md index fc48cf142..cbacccfcf 100644 --- a/website/docs/tutorials/react-native.md +++ b/website/docs/tutorials/react-native.md @@ -19,9 +19,9 @@ See [here](https://github.com/facebook/hermes/issues/23) for details about `Intl ## Polyfilling Intl apis -React Native does not support all Intl features out of the box and we need to polyfill [`Intl.Locale`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale) using [`@formatjs/intl-locale`](https://formatjs.io/docs/polyfills/intl-locale/) and [`Intl.PluralRules`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules) using [`@formatjs/intl-pluralrules`](https://formatjs.io/docs/polyfills/intl-pluralrules). +React Native does not support all `Intl` features out of the box and we need to polyfill [`Intl.Locale`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale) using [`@formatjs/intl-locale`](https://formatjs.io/docs/polyfills/intl-locale/) and [`Intl.PluralRules`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules) using [`@formatjs/intl-pluralrules`](https://formatjs.io/docs/polyfills/intl-pluralrules). Please note that installing the `Intl` polyfills can significantly increase your bundle size. -Follow their installation instructions and then import the polyfills at the top of your application entry file. +Follow the polyfill installation instructions and then import them at the top of your application entry file. ## Example component @@ -33,7 +33,7 @@ import React from 'react'; import { StyleSheet, Text, View, Alert, SafeAreaView, Button } from 'react-native'; export const AppRoot = () => { - const [messages, setMessages] = useState([]); + const [messages, setMessages] = useState([]); const markAllAsRead = () => { Alert.alert("", "Do you want to set all your messages as read?", [ @@ -88,8 +88,8 @@ As you can see, it's a simple mailbox application with only one screen. ## Internationalization in React (Native) -:::caution Note -TL;DR: There are several ways to render translations: You may use the [`Trans`](/docs/ref/react.md#trans) component or the [`useLingui`](/docs/ref/react.md#withi18n) hook together with the `t` macro. When you change the active locale or load new messages, all the components that consume the Context provided by `I18nProvider` will re-render, making sure the UI shows the correct translations. +:::tip TL;DR +There are several ways to render translations: You may use the [`Trans`](/docs/ref/react.md#trans) component or the [`useLingui`](/docs/ref/react.md#withi18n) hook together with the [`t`](/docs/ref/macro.md#t) or [`msg`](/ref/macro#definemessage) macros. When you change the active locale or load new messages, all the components that consume the Lingui context provided by [`I18nProvider`](/docs/ref/react.md#i18nprovider) will re-render, making sure the UI shows the correct translations. ::: Not surprisingly, this part isn't too different from the [React tutorial](/docs/tutorials/react.md). @@ -128,9 +128,9 @@ const { i18n } = useLingui()