Localization in React Tab component

29 Aug 202310 minutes to read

Localization library allows to localize the default text content of the Tab to different cultures using the locale property. In Tab, the close button’s tooltip text alone will be localize based on culture. The close button is shown on tab header when enabled showCloseButton property.

Locale key en-US (default)
closeButtonTitle Close

Loading translations

To load translation object in an application use load function of L10n class.

In the below sample, French culture is set to Tab and change the close button’s tooltip text.

import { L10n } from '@syncfusion/ej2-base';
import { TabComponent, TabItemDirective, TabItemsDirective } from '@syncfusion/ej2-react-navigations';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
L10n.load({
    'fr-BE': {
        'tab': {
            'closeButtonTitle': "Fermer"
        }
    }
});
const ReactApp = () => {
    const headerText = [{ text: "HTML" }, { text: "C Sharp(C#)" }, { text: "Java" }];
    const htmlContent = () => {
        return <div>
      HyperText Markup Language, commonly referred to as HTML, is the standard markup language used to create web pages. Along with CSS, and JavaScript, HTML is a cornerstone technology, used by most websites to create visually engaging web pages, user interfaces for web applications, and user interfaces for many mobile applications.[1] Web browsers can read HTML files and render them into visible or audible web pages. HTML describes the structure of a website semantically along with cues for presentation, making it a markup language, rather than a programming language.
    </div>;
    }
    const csharpContent = () => {
        return <div>
      C# is intended to be a simple, modern, general-purpose, object-oriented programming language. Its development team is led by Anders Hejlsberg. The most recent version is C# 5.0, which was released on August 15, 2012.
    </div>;
    }
    const javaContent = () => {
        return <div>
      Java is a set of computer software and specifications developed by Sun Microsystems, later acquired by Oracle Corporation, that provides a system for developing application software and deploying it in a cross-mobile phones to platform computing environment. Java is used in a wide variety of computing platforms from embedded devices and enterprise servers and supercomputers. While less common, Java applets run in secure, sandboxed environments to provide many features of native applications and can be embedded in HTML pages.
    </div>;
    }
    return (<TabComponent heightAdjustMode='Auto' locale="fr-BE" showCloseButton={true}>
      <TabItemsDirective>
        <TabItemDirective header={headerText[0]} content={htmlContent}/>
        <TabItemDirective header={headerText[1]} content={csharpContent}/>
        <TabItemDirective header={headerText[2]} content={javaContent}/>
      </TabItemsDirective>
    </TabComponent>);
}
const root = ReactDOM.createRoot(document.getElementById('element'));
root.render(<ReactApp />);
import { L10n } from '@syncfusion/ej2-base';
import { TabComponent, TabItemDirective, TabItemsDirective } from '@syncfusion/ej2-react-navigations';
import * as React from 'react';
import * as ReactDOM from 'react-dom';

L10n.load({
  'fr-BE': {
    'tab': {
      'closeButtonTitle': "Fermer"
    }
  }
});

const ReactApp = () => {
  const headerText: any = [{ text: "HTML" }, { text: "C Sharp(C#)" }, { text: "Java" }];

  const htmlContent = () => {
    return <div>
      HyperText Markup Language, commonly referred to as HTML, is the standard markup language used to create web pages. Along with CSS, and JavaScript, HTML is a cornerstone technology, used by most websites to create visually engaging web pages, user interfaces for web applications, and user interfaces for many mobile applications.[1] Web browsers can read HTML files and render them into visible or audible web pages. HTML describes the structure of a website semantically along with cues for presentation, making it a markup language, rather than a programming language.
    </div>;
  }
  const csharpContent = () => {
    return <div>
      C# is intended to be a simple, modern, general-purpose, object-oriented programming language. Its development team is led by Anders Hejlsberg. The most recent version is C# 5.0, which was released on August 15, 2012.
    </div>;
  }
  const javaContent = () => {
    return <div>
      Java is a set of computer software and specifications developed by Sun Microsystems, later acquired by Oracle Corporation, that provides a system for developing application software and deploying it in a cross-mobile phones to platform computing environment. Java is used in a wide variety of computing platforms from embedded devices and enterprise servers and supercomputers. While less common, Java applets run in secure, sandboxed environments to provide many features of native applications and can be embedded in HTML pages.
    </div>;
  }
  return (
    <TabComponent heightAdjustMode='Auto' locale="fr-BE" showCloseButton={true}>
      <TabItemsDirective>
        <TabItemDirective header={headerText[0]} content={htmlContent} />
        <TabItemDirective header={headerText[1]} content={csharpContent} />
        <TabItemDirective header={headerText[2]} content={javaContent} />
      </TabItemsDirective>
    </TabComponent>
  );
}
const root = ReactDOM.createRoot(document.getElementById('element'));
root.render(<ReactApp />);
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Syncfusion React Tab</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Essential JS 2 for React Components" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <link href="https://cdn.syncfusion.com/ej2/25.1.35/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>
    <div id='container'>
        <div id='element'>
                <div id='loader'>Loading</div>
        </div>
    </div>
</body>

</html>