{"id":14,"date":"2024-12-15T21:38:40","date_gmt":"2024-12-15T21:38:40","guid":{"rendered":"https:\/\/fullstacknotes.netblocs.com\/?p=14"},"modified":"2024-12-18T09:54:58","modified_gmt":"2024-12-18T09:54:58","slug":"must-know-react-libraries-react-intl","status":"publish","type":"post","link":"https:\/\/netblocs.com\/fullstacknotes\/must-know-react-libraries-react-intl\/","title":{"rendered":"Best React Libraries: React-Intl"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"682\" src=\"https:\/\/fullstacknotes.netblocs.com\/wp-content\/uploads\/2024\/12\/pexels-pixabay-270557-1-1024x682.jpg\" alt=\"\" class=\"wp-image-89\" style=\"width:300px\" srcset=\"https:\/\/netblocs.com\/fullstacknotes\/wp-content\/uploads\/2024\/12\/pexels-pixabay-270557-1-1024x682.jpg 1024w, https:\/\/netblocs.com\/fullstacknotes\/wp-content\/uploads\/2024\/12\/pexels-pixabay-270557-1-300x200.jpg 300w, https:\/\/netblocs.com\/fullstacknotes\/wp-content\/uploads\/2024\/12\/pexels-pixabay-270557-1-768x511.jpg 768w, https:\/\/netblocs.com\/fullstacknotes\/wp-content\/uploads\/2024\/12\/pexels-pixabay-270557-1-1536x1023.jpg 1536w, https:\/\/netblocs.com\/fullstacknotes\/wp-content\/uploads\/2024\/12\/pexels-pixabay-270557-1-2048x1364.jpg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\">What is <strong>react-intl<\/strong>?<\/h3>\n\n\n\n<p><strong>react-intl<\/strong> is a powerful library that simplifies the process of adding internationalization (i18n) and localization (l10n) to your React applications. With react-intl, you can seamlessly display text, dates, numbers, and currencies tailored to the user&#8217;s language and formatting preferences.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">What is <strong>FormattedMessage<\/strong>?<\/h3>\n\n\n\n<p><strong>FormattedMessage<\/strong> is a key feature of react-intl, designed to make displaying translated messages in your app effortless. It retrieves the appropriate text from a translation file using unique message IDs and dynamically adjusts the content based on the user&#8217;s selected language.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Quick Start Guide to react-intl<\/h3>\n\n\n\n<p>Here\u2019s how to integrate react-intl into your React application step by step:<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>1. Creating Translation Files<\/strong><\/h4>\n\n\n\n<p>First, define translation files for your supported languages. Save these files in the <code>src\/locales<\/code> directory.<\/p>\n\n\n\n<p><strong>English Translations (<code>src\/locales\/en.json<\/code>)<\/strong>:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#232136\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"{\n  &quot;greeting&quot;: &quot;Hello, {name}!&quot;,\n  &quot;welcome&quot;: &quot;Welcome to our application!&quot;\n}\" style=\"color:#e0def4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki rose-pine-moon\" style=\"background-color: #232136\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #908CAA\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #F6C177\">&quot;greeting&quot;<\/span><span style=\"color: #E0DEF4\">: <\/span><span style=\"color: #F6C177\">&quot;Hello, {name}!&quot;<\/span><span style=\"color: #908CAA\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #F6C177\">&quot;welcome&quot;<\/span><span style=\"color: #E0DEF4\">: <\/span><span style=\"color: #F6C177\">&quot;Welcome to our application!&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #908CAA\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>Turkish Translations (<code>src\/locales\/tr.json<\/code>)<\/strong>:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#232136\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"{\n  &quot;greeting&quot;: &quot;Merhaba, {name}!&quot;,\n  &quot;welcome&quot;: &quot;Uygulamam\u0131za ho\u015f geldiniz!&quot;\n}\" style=\"color:#e0def4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki rose-pine-moon\" style=\"background-color: #232136\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #908CAA\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #F6C177\">&quot;greeting&quot;<\/span><span style=\"color: #E0DEF4\">: <\/span><span style=\"color: #F6C177\">&quot;Merhaba, {name}!&quot;<\/span><span style=\"color: #908CAA\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #F6C177\">&quot;welcome&quot;<\/span><span style=\"color: #E0DEF4\">: <\/span><span style=\"color: #F6C177\">&quot;Uygulamam\u0131za ho\u015f geldiniz!&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #908CAA\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>2. Setting Up IntlProvider in App.js<\/strong><\/h4>\n\n\n\n<p>Next, wrap your app in the <code>IntlProvider<\/code> component to manage translations and the active language.<\/p>\n\n\n\n<p><strong><code>src\/App.js<\/code>:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#232136\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"import React, { useState } from &quot;react&quot;;\nimport { IntlProvider } from &quot;react-intl&quot;;\nimport Greeting from &quot;.\/Greeting&quot;;\n\n\/\/ Translation files\nimport enMessages from &quot;.\/locales\/en.json&quot;;\nimport trMessages from &quot;.\/locales\/tr.json&quot;;\n\n\/\/ Language-to-messages mapping\nconst messages = {\n  en: enMessages,\n  tr: trMessages,\n};\n\nfunction App() {\n  const [locale, setLocale] = useState(&quot;en&quot;); \/\/ Default language: English\n\n  return (\n    &lt;IntlProvider locale={locale} messages={messages[locale]}&gt;\n      &lt;div className=&quot;App&quot;&gt;\n        {\/* Language switch buttons *\/}\n        &lt;button onClick={() =&gt; setLocale(&quot;en&quot;)}&gt;English&lt;\/button&gt;\n        &lt;button onClick={() =&gt; setLocale(&quot;tr&quot;)}&gt;T\u00fcrk\u00e7e&lt;\/button&gt;\n\n        {\/* Greeting component *\/}\n        &lt;Greeting name=&quot;Ali&quot; \/&gt;\n      &lt;\/div&gt;\n    &lt;\/IntlProvider&gt;\n  );\n}\n\nexport default App;\" style=\"color:#e0def4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki rose-pine-moon\" style=\"background-color: #232136\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #3E8FB0\">import <\/span><span style=\"color: #E0DEF4; font-style: italic\">React<\/span><span style=\"color: #908CAA\">,<\/span><span style=\"color: #3E8FB0\"> <\/span><span style=\"color: #908CAA\">{<\/span><span style=\"color: #3E8FB0\"> <\/span><span style=\"color: #E0DEF4; font-style: italic\">useState<\/span><span style=\"color: #3E8FB0\"> <\/span><span style=\"color: #908CAA\">}<\/span><span style=\"color: #3E8FB0\"> from <\/span><span style=\"color: #F6C177\">&quot;react&quot;<\/span><span style=\"color: #908CAA\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">import <\/span><span style=\"color: #908CAA\">{<\/span><span style=\"color: #3E8FB0\"> <\/span><span style=\"color: #E0DEF4; font-style: italic\">IntlProvider<\/span><span style=\"color: #3E8FB0\"> <\/span><span style=\"color: #908CAA\">}<\/span><span style=\"color: #3E8FB0\"> from <\/span><span style=\"color: #F6C177\">&quot;react-intl&quot;<\/span><span style=\"color: #908CAA\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">import <\/span><span style=\"color: #E0DEF4; font-style: italic\">Greeting<\/span><span style=\"color: #3E8FB0\"> from <\/span><span style=\"color: #F6C177\">&quot;.\/Greeting&quot;<\/span><span style=\"color: #908CAA\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #908CAA; font-style: italic\">\/\/<\/span><span style=\"color: #6E6A86; font-style: italic\"> Translation files<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">import <\/span><span style=\"color: #E0DEF4; font-style: italic\">enMessages<\/span><span style=\"color: #3E8FB0\"> from <\/span><span style=\"color: #F6C177\">&quot;.\/locales\/en.json&quot;<\/span><span style=\"color: #908CAA\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">import <\/span><span style=\"color: #E0DEF4; font-style: italic\">trMessages<\/span><span style=\"color: #3E8FB0\"> from <\/span><span style=\"color: #F6C177\">&quot;.\/locales\/tr.json&quot;<\/span><span style=\"color: #908CAA\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #908CAA; font-style: italic\">\/\/<\/span><span style=\"color: #6E6A86; font-style: italic\"> Language-to-messages mapping<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">const<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #E0DEF4; font-style: italic\">messages<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #908CAA\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">  en<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #E0DEF4; font-style: italic\">enMessages<\/span><span style=\"color: #908CAA\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">  tr<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #E0DEF4; font-style: italic\">trMessages<\/span><span style=\"color: #908CAA\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #908CAA\">};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">function<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #EA9A97\">App<\/span><span style=\"color: #908CAA\">()<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #908CAA\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #3E8FB0\">const<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #908CAA\">[<\/span><span style=\"color: #E0DEF4; font-style: italic\">locale<\/span><span style=\"color: #908CAA\">,<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #E0DEF4; font-style: italic\">setLocale<\/span><span style=\"color: #908CAA\">]<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #EA9A97\">useState<\/span><span style=\"color: #E0DEF4\">(<\/span><span style=\"color: #F6C177\">&quot;en&quot;<\/span><span style=\"color: #E0DEF4\">)<\/span><span style=\"color: #908CAA\">;<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #908CAA; font-style: italic\">\/\/<\/span><span style=\"color: #6E6A86; font-style: italic\"> Default language: English<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #3E8FB0\">return<\/span><span style=\"color: #E0DEF4\"> (<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    <\/span><span style=\"color: #6E6A86\">&lt;<\/span><span style=\"color: #9CCFD8\">IntlProvider<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #C4A7E7; font-style: italic\">locale<\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #908CAA\">{<\/span><span style=\"color: #E0DEF4; font-style: italic\">locale<\/span><span style=\"color: #908CAA\">}<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #C4A7E7; font-style: italic\">messages<\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #908CAA\">{<\/span><span style=\"color: #E0DEF4; font-style: italic\">messages<\/span><span style=\"color: #E0DEF4\">[<\/span><span style=\"color: #E0DEF4; font-style: italic\">locale<\/span><span style=\"color: #E0DEF4\">]<\/span><span style=\"color: #908CAA\">}<\/span><span style=\"color: #6E6A86\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">      <\/span><span style=\"color: #6E6A86\">&lt;<\/span><span style=\"color: #9CCFD8\">div<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #C4A7E7; font-style: italic\">className<\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #F6C177\">&quot;App&quot;<\/span><span style=\"color: #6E6A86\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #908CAA\">{<\/span><span style=\"color: #908CAA; font-style: italic\">\/*<\/span><span style=\"color: #6E6A86; font-style: italic\"> Language switch buttons <\/span><span style=\"color: #908CAA; font-style: italic\">*\/<\/span><span style=\"color: #908CAA\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #6E6A86\">&lt;<\/span><span style=\"color: #9CCFD8\">button<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #C4A7E7; font-style: italic\">onClick<\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #908CAA\">{()<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">=&gt;<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #EA9A97\">setLocale<\/span><span style=\"color: #E0DEF4\">(<\/span><span style=\"color: #F6C177\">&quot;en&quot;<\/span><span style=\"color: #E0DEF4\">)<\/span><span style=\"color: #908CAA\">}<\/span><span style=\"color: #6E6A86\">&gt;<\/span><span style=\"color: #E0DEF4\">English<\/span><span style=\"color: #6E6A86\">&lt;\/<\/span><span style=\"color: #9CCFD8\">button<\/span><span style=\"color: #6E6A86\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #6E6A86\">&lt;<\/span><span style=\"color: #9CCFD8\">button<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #C4A7E7; font-style: italic\">onClick<\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #908CAA\">{()<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">=&gt;<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #EA9A97\">setLocale<\/span><span style=\"color: #E0DEF4\">(<\/span><span style=\"color: #F6C177\">&quot;tr&quot;<\/span><span style=\"color: #E0DEF4\">)<\/span><span style=\"color: #908CAA\">}<\/span><span style=\"color: #6E6A86\">&gt;<\/span><span style=\"color: #E0DEF4\">T\u00fcrk\u00e7e<\/span><span style=\"color: #6E6A86\">&lt;\/<\/span><span style=\"color: #9CCFD8\">button<\/span><span style=\"color: #6E6A86\">&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #908CAA\">{<\/span><span style=\"color: #908CAA; font-style: italic\">\/*<\/span><span style=\"color: #6E6A86; font-style: italic\"> Greeting component <\/span><span style=\"color: #908CAA; font-style: italic\">*\/<\/span><span style=\"color: #908CAA\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #6E6A86\">&lt;<\/span><span style=\"color: #9CCFD8\">Greeting<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #C4A7E7; font-style: italic\">name<\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #F6C177\">&quot;Ali&quot;<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #6E6A86\">\/&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">      <\/span><span style=\"color: #6E6A86\">&lt;\/<\/span><span style=\"color: #9CCFD8\">div<\/span><span style=\"color: #6E6A86\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    <\/span><span style=\"color: #6E6A86\">&lt;\/<\/span><span style=\"color: #9CCFD8\">IntlProvider<\/span><span style=\"color: #6E6A86\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">  )<\/span><span style=\"color: #908CAA\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #908CAA\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">export default <\/span><span style=\"color: #E0DEF4; font-style: italic\">App<\/span><span style=\"color: #908CAA\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>3. Using FormattedMessage in a Child Component<\/strong><\/h4>\n\n\n\n<p>Create a child component (e.g., <code>Greeting.js<\/code>) to render dynamic and localized content.<\/p>\n\n\n\n<p><strong><code>src\/Greeting.js<\/code>:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#232136\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"import React from &quot;react&quot;;\nimport { FormattedMessage } from &quot;react-intl&quot;;\n\nfunction Greeting({ name }) {\n  return (\n    &lt;div&gt;\n      &lt;FormattedMessage id=&quot;greeting&quot; values={{ name }} \/&gt;\n      &lt;FormattedMessage id=&quot;welcome&quot; \/&gt;\n    &lt;\/div&gt;\n  );\n}\n\nexport default Greeting;\" style=\"color:#e0def4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki rose-pine-moon\" style=\"background-color: #232136\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #3E8FB0\">import <\/span><span style=\"color: #E0DEF4; font-style: italic\">React<\/span><span style=\"color: #3E8FB0\"> from <\/span><span style=\"color: #F6C177\">&quot;react&quot;<\/span><span style=\"color: #908CAA\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">import <\/span><span style=\"color: #908CAA\">{<\/span><span style=\"color: #3E8FB0\"> <\/span><span style=\"color: #E0DEF4; font-style: italic\">FormattedMessage<\/span><span style=\"color: #3E8FB0\"> <\/span><span style=\"color: #908CAA\">}<\/span><span style=\"color: #3E8FB0\"> from <\/span><span style=\"color: #F6C177\">&quot;react-intl&quot;<\/span><span style=\"color: #908CAA\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">function<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #EA9A97\">Greeting<\/span><span style=\"color: #908CAA\">({<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #C4A7E7; font-style: italic\">name<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #908CAA\">})<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #908CAA\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #3E8FB0\">return<\/span><span style=\"color: #E0DEF4\"> (<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    <\/span><span style=\"color: #6E6A86\">&lt;<\/span><span style=\"color: #9CCFD8\">div<\/span><span style=\"color: #6E6A86\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">      <\/span><span style=\"color: #6E6A86\">&lt;<\/span><span style=\"color: #9CCFD8\">FormattedMessage<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #C4A7E7; font-style: italic\">id<\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #F6C177\">&quot;greeting&quot;<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #C4A7E7; font-style: italic\">values<\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #908CAA\">{{<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #E0DEF4; font-style: italic\">name<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #908CAA\">}}<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #6E6A86\">\/&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">      <\/span><span style=\"color: #6E6A86\">&lt;<\/span><span style=\"color: #9CCFD8\">FormattedMessage<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #C4A7E7; font-style: italic\">id<\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #F6C177\">&quot;welcome&quot;<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #6E6A86\">\/&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    <\/span><span style=\"color: #6E6A86\">&lt;\/<\/span><span style=\"color: #9CCFD8\">div<\/span><span style=\"color: #6E6A86\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">  )<\/span><span style=\"color: #908CAA\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #908CAA\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">export default <\/span><span style=\"color: #E0DEF4; font-style: italic\">Greeting<\/span><span style=\"color: #908CAA\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>4. Programmatically Accessing Translations with useIntl<\/strong><\/h4>\n\n\n\n<p>For programmatic access to translations, use the <code>useIntl<\/code> hook, which provides the <code>intl.formatMessage<\/code> function to retrieve messages dynamically.<\/p>\n\n\n\n<p><strong><code>src\/DocumentName.js<\/code>:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#232136\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"import React from &quot;react&quot;;\nimport { useIntl } from &quot;react-intl&quot;;\n\nfunction DocumentName() {\n  const intl = useIntl();\n\n  \/\/ Retrieve the translated message by ID\n  const docName = intl.formatMessage({ id: &quot;doc_name&quot; });\n\n  return &lt;p&gt;{docName}&lt;\/p&gt;;\n}\n\nexport default DocumentName;\" style=\"color:#e0def4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki rose-pine-moon\" style=\"background-color: #232136\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #3E8FB0\">import <\/span><span style=\"color: #E0DEF4; font-style: italic\">React<\/span><span style=\"color: #3E8FB0\"> from <\/span><span style=\"color: #F6C177\">&quot;react&quot;<\/span><span style=\"color: #908CAA\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">import <\/span><span style=\"color: #908CAA\">{<\/span><span style=\"color: #3E8FB0\"> <\/span><span style=\"color: #E0DEF4; font-style: italic\">useIntl<\/span><span style=\"color: #3E8FB0\"> <\/span><span style=\"color: #908CAA\">}<\/span><span style=\"color: #3E8FB0\"> from <\/span><span style=\"color: #F6C177\">&quot;react-intl&quot;<\/span><span style=\"color: #908CAA\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">function<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #EA9A97\">DocumentName<\/span><span style=\"color: #908CAA\">()<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #908CAA\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #3E8FB0\">const<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #E0DEF4; font-style: italic\">intl<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #EA9A97\">useIntl<\/span><span style=\"color: #E0DEF4\">()<\/span><span style=\"color: #908CAA\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #908CAA\">  <\/span><span style=\"color: #908CAA; font-style: italic\">\/\/<\/span><span style=\"color: #6E6A86; font-style: italic\"> Retrieve the translated message by ID<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #3E8FB0\">const<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #E0DEF4; font-style: italic\">docName<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #E0DEF4; font-style: italic\">intl<\/span><span style=\"color: #3E8FB0\">.<\/span><span style=\"color: #EA9A97\">formatMessage<\/span><span style=\"color: #E0DEF4\">(<\/span><span style=\"color: #908CAA\">{<\/span><span style=\"color: #E0DEF4\"> id<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;doc_name&quot;<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #908CAA\">}<\/span><span style=\"color: #E0DEF4\">)<\/span><span style=\"color: #908CAA\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #3E8FB0\">return<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #6E6A86\">&lt;<\/span><span style=\"color: #9CCFD8\">p<\/span><span style=\"color: #6E6A86\">&gt;<\/span><span style=\"color: #908CAA\">{<\/span><span style=\"color: #E0DEF4; font-style: italic\">docName<\/span><span style=\"color: #908CAA\">}<\/span><span style=\"color: #6E6A86\">&lt;\/<\/span><span style=\"color: #9CCFD8\">p<\/span><span style=\"color: #6E6A86\">&gt;<\/span><span style=\"color: #908CAA\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #908CAA\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">export default <\/span><span style=\"color: #E0DEF4; font-style: italic\">DocumentName<\/span><span style=\"color: #908CAA\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Why Choose react-intl?<\/h3>\n\n\n\n<p>With its intuitive API and robust features, <strong>react-intl<\/strong> empowers developers to deliver personalized and localized user experiences, making your applications accessible to a global audience.<\/p>\n\n\n\n<p>Start integrating <strong>react-intl<\/strong> today and take your React projects to the next level!<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><em>Have you tried react-intl in your projects? Share your experience in the comments below!<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is react-intl? react-intl is a powerful library that simplifies the process of adding internationalization (i18n) and localization (l10n) to your React applications. With react-intl, you can seamlessly display text,&hellip;<\/p>\n","protected":false},"author":1,"featured_media":21,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,11,21],"tags":[16,17,15,18,14,19],"class_list":["post-14","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-libraries","category-react","category-react-libraries","tag-formattedmessage","tag-intl","tag-libraries","tag-localization","tag-react","tag-react-libraries"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/netblocs.com\/fullstacknotes\/wp-json\/wp\/v2\/posts\/14","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/netblocs.com\/fullstacknotes\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/netblocs.com\/fullstacknotes\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/netblocs.com\/fullstacknotes\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/netblocs.com\/fullstacknotes\/wp-json\/wp\/v2\/comments?post=14"}],"version-history":[{"count":6,"href":"https:\/\/netblocs.com\/fullstacknotes\/wp-json\/wp\/v2\/posts\/14\/revisions"}],"predecessor-version":[{"id":104,"href":"https:\/\/netblocs.com\/fullstacknotes\/wp-json\/wp\/v2\/posts\/14\/revisions\/104"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/netblocs.com\/fullstacknotes\/wp-json\/wp\/v2\/media\/21"}],"wp:attachment":[{"href":"https:\/\/netblocs.com\/fullstacknotes\/wp-json\/wp\/v2\/media?parent=14"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/netblocs.com\/fullstacknotes\/wp-json\/wp\/v2\/categories?post=14"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/netblocs.com\/fullstacknotes\/wp-json\/wp\/v2\/tags?post=14"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}