What is rtl-detect?
The rtl-detect npm package is used to detect if a given language is written in a right-to-left (RTL) script. This can be useful for internationalization and localization purposes, especially when dealing with languages like Arabic, Hebrew, and Persian.
What are rtl-detect's main functionalities?
Detect if a language is RTL
This feature allows you to check if a given language code corresponds to a right-to-left language. In this example, 'ar' (Arabic) is checked and returns true.
const rtlDetect = require('rtl-detect');
const isRtl = rtlDetect.isRtlLang('ar');
console.log(isRtl); // true
Get list of RTL languages
This feature provides a list of all language codes that are written in a right-to-left script. This can be useful for dynamically adjusting UI elements based on the user's language.
const rtlDetect = require('rtl-detect');
const rtlLanguages = rtlDetect.getRtlLangs();
console.log(rtlLanguages); // ['ar', 'he', 'fa', ...]
Other packages similar to rtl-detect
rtlcss
rtlcss is a framework for transforming CSS from left-to-right (LTR) to right-to-left (RTL). While rtl-detect focuses on detecting RTL languages, rtlcss is more about converting CSS styles to support RTL layouts.
bidi-js
bidi-js is a JavaScript library for handling bidirectional text. It provides utilities for detecting and managing text direction, similar to rtl-detect, but with more focus on text processing and manipulation.
i18next
i18next is an internationalization framework for JavaScript. It provides extensive support for language detection, including RTL languages, but also offers a wide range of other localization features such as translation and formatting.
rtl-detect
This library will help you to detect if the locale is right-to-left language or not.
Usage
require rtl-detect lib
var rtlDetect = require('rtl-detect');
isRtlLang
This function will check if the locale is right-to-left language or not.
Examples:
var isRtl = rtlDetect.isRtlLang('ar-JO');
var isRtl = rtlDetect.isRtlLang('ar_JO');
var isRtl = rtlDetect.isRtlLang('ar');
var isRtl = rtlDetect.isRtlLang('en-US');
getLangDir
This function will get language direction for the locale.
Examples:
var langDir = rtlDetect.getLangDir('ar-JO');
var langDir = rtlDetect.getLangDir('ar_JO');
var langDir = rtlDetect.getLangDir('ar');
var langDir = rtlDetect.getLangDir('en-US');
Copyright 2015, Yahoo! Inc.