Blueprint by Tiny
Return to Tiny.cloud
Return to Tiny.cloudTry TinyMCE for Free
Search by

Setting text direction for internationalization with TinyMCE

Vikram Aruchamy

February 2nd, 2022

Written by

Vikram Aruchamy

Category

How-to Use TinyMCE

One of the most important parts of developing software is targeting markets in different countries, which means (where appropriate) you use the language of those countries. For example, in order to serve the Israeli market, the software must support Hebrew. This concept is called internationalization and to support internationalization, it’s vital to have the ability to change the direction of text.

Rich text editors have the ability to change the text direction. They do this through HTML rtl and ltr options (that’s right to left, and left to right).

If the rich text editor is a What You See Is What You Get (WYSIWYG) then developers and content creators can publish their content without needing in-depth knowledge of text direction.

How to set text direction for internationalization

To adapt a product or software to meet the language or culture of a specific market, you must define the locale, which is a set of parameters detailing user preferences for a specific location such as; language, date-time format, currency format, and other settings.

When working with an RTE, you need to configure the text directions based on the default language. Thankfully, you can set the HTML text direction and other details automatically with TinyMCE based on the configured language. For example, when the language Hebrew is configured, by default, the editor text direction will be right to left. 

Can’t you set text direction in just one place?

While you can set text direction, and let each page element inherit the configuration (you can also set text direction with TinyMCE), users may need to create or edit an English-language document going left to right, but still want to have user interface (UI) options in Hebrew. This can be achieved through setting up TinyMCE’s directionality option for internationalization, and this tutorial explains how to do it.

Setting up TinyMCE

Your aim: create a project using TinyMCE, configure the language for the UI, and set the text direction to be used in the editor window, changing to and from ltr and rtl.

The TinyMCE editor supports a cloud-hosted version and a self-hosted version – these instructions use the self-hosted version.

Collecting the self hosted files

  1. Navigate to the downloads page
  2. Download the community version of the TinyMCE editor, and extract it to your desired location.
  3. Find a folder named \tinymce\js\tinymce inside the extracted folder. This is the root folder. It contains all the necessary files for creating the TinyMCE editor. It also contains folders, plugins, and langs, used to install additional plugins and languages, respectively.

Setting up the editor

  1. Create an HTML file in the root folder with a text area, which will act as an editor window.

  2. Use the following snippet to create a webpage with a text area.

<!DOCTYPE html>
<html>
<head>
<title>
My TinyMCE Editor
</title>
</head>
<body>
  <textarea>
    Welcome to TinyMCE Editor!
  </textarea>
</body>
</html>

Initializing TinyMCE

To initialize the TinyMCE editor, you need to add the TinyMCE reference and the tiny.init() method.

  1. Add the following script in the <head> tag of your HTML file. It adds a reference to the TinyMCE JavaScript file you’ve downloaded.

<script src="js/tinymce/tinymce.min.js" referrerpolicy="origin"></script>;
  1. Add this script at the bottom of your <body> tag to initialize the TinyMCE editor.

 <script>
tinymce.init({
      selector: 'textarea',
      plugins: 'table code colorpicker textcolor',
     toolbar: 'table code bold italic alignleft aligncenter alignright alignjustify | outdent indent ',
      toolbar_mode: 'floating'
    });
</script>

In the above code:

  • selector: 'textarea' specifies the CSS selector to find the text area you created earlier.
  • plugins: specifies the list of TinyMCE plugins to be used in your editor. Open-source plugins are available by default when you download the community version of the TinyMCE editor. You can find the list on the plugins page.
  • toolbar: enables and configures the items in the toolbar displayed beneath the Menu bar. Use | to add separators within the toolbar icons.
  • toolbar_mode: configures how the toolbar icons are accommodated in the toolbar in different screen sizes. Possible values are listed in the toolbar documentation.

Save the file as index.htm in the root folder. When you load the file in the browser, you should see something like this:

TinyMCE working in the browser

Now configure internationalization.

Localizing the interface

Installing language packages

A language package contains every UI text label in a specific language.

In order to configure the UI text in a specific language:

  1. Download the language package from the Language Packages page and extract it to the js/tinymce/langs folder of the TinyMCE installation location.
  2. Download and install the language package Hebrew. Remember, this requires a right to left direction. You’ll configure options and directionality around that.

Configuring language and text direction

Understand the following components for setting TinyMCE for internationalization and text direction:

  • The language option is used to configure the language of the UI. The UI text direction is automatically configured based on the language package.
  • The directionality option is used to configure the text direction in the editor text area.

The language and directionality options are configured in the init() method, which is used to initialize the editor.

To configure the language of the UI:

  1. Extract file name of the downloaded language package. For example, the downloaded language package has the file name he_IL.js, which you need to use in the language option.

  2. Add the following option in the tinymce.init() method to configure Hebrew as the UI language:

language: "he_IL";

When you configure the language, the text direction of the UI will be automatically adapted to match the language. In this case, the text will move from right to left.

TinyMCE with text directionality enabled

Reconfigure and adjust text direction 

TinyMCE also allows you to configure the desired text direction in the editor using the directionality option, which is independent of the configured language. This way, you can adjust the text direction, changing it from left to right as needed. To create or work with English text, you set the directionality to ltr, or rtl:

directionality : 'ltr'

With this option added, the editor will have the language set as Hebrew and the text direction from left to right:

TinyMCE set up with text directionality and language enabled in the toolbar and menu bar.

You can check on the TinyMCE documentation to find out more about the directionality plugin.

The final HTML file with language and text direction should look like this:

<!DOCTYPE html>
<html>
<head>
  <script src="js/tinymce/tinymce.min.js" referrerpolicy="origin"></script>
</head>
<body>
  <textarea>
    Welcome to TinyMCE!
  </textarea>
  <script>
    tinymce.init({
      selector: 'textarea',
      plugins: 'table code colorpicker textcolor',
      toolbar: 'table code bold italic alignleft aligncenter alignright alignjustify | outdent indent |',
      toolbar_mode: 'floating',
	  language: 'he_IL',
	  directionality : 'ltr'
	  })
  </script>
</body>
</html>

Conclusion

To better serve your users in multiple countries and regions, you need to present your products in multiple languages. TinyMCE allows you to set HTML text direction while providing many other customizable features to internationalize.

If you’d like to try this out for yourself, you can sign up for a FREE API key, and set TinyMCE text direction on your website with Tiny Cloud.

TinyMCEUse Cases
byVikram Aruchamy

AWS Community Builder, Technical writer, and Blogger. Vikram's topics of interest are AWS, Python, Machine learning.

Related Articles

  • How-to Use TinyMCE

    How to set up a CMS editor with TinyMCE Cloud

    by Joe Robinson in How-to Use TinyMCE
Subscribe for the latest insights served straight to your inbox every month.

Deploy TinyMCE in just 6 lines of code

Built to scale. Developed in open source. Designed to innovate.

Begin with your FREE API Key
Tiny Editor
Tiny logo
Privacy Policy - Terms of Use© 2022 Tiny Technologies Inc.TinyMCE® and Tiny® are registered trademarks of Tiny Technologies, Inc.

Products

  • TinyMCE
  • Tiny Drive
  • Customer Stories
  • Pricing