• Stars
    star
    174
  • Rank 218,045 (Top 5 %)
  • Language
    TypeScript
  • Created about 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Transliteration component for React with support for over 30 langauges. Burhanuddin → बुरहानुद्दीन

React Transliterate

Transliteration component for React with support for over 30 languages. Uses API from Google Input Tools

NPM

Demo

See Demo

Install

npm install --save react-transliterate

OR

yarn add react-transliterate

Usage

Basic example

import React, { useState } from "react";

import { ReactTransliterate } from "react-transliterate";
import "react-transliterate/dist/index.css";

const App = () => {
  const [text, setText] = useState("");

  return (
    <ReactTransliterate
      value={text}
      onChangeText={(text) => {
        setText(text);
      }}
      lang="hi"
    />
  );
};

export default App;

With custom component

import React, { useState } from "react";

import { ReactTransliterate } from "react-transliterate";
import "react-transliterate/dist/index.css";

const App = () => {
  const [text, setText] = useState("");

  return (
    <ReactTransliterate
      renderComponent={(props) => <textarea {...props} />}
      value={text}
      onChangeText={(text) => {
        setText(text);
      }}
      lang="hi"
    />
  );
};

export default App;

Usage with TypeScript

import React, { useState } from "react";

import { ReactTransliterate, Language } from "react-transliterate";
import "react-transliterate/dist/index.css";

const App = () => {
  const [text, setText] = useState("");
  const [lang, setLang] = useState<Language>("hi");

  return (
    <ReactTransliterate
      renderComponent={(props) => <textarea {...props} />}
      value={text}
      onChangeText={(text) => {
        setText(text);
      }}
      lang={lang}
    />
  );
};

export default App;

With material ui

import React, { useState } from "react";

import { ReactTransliterate, Language } from "react-transliterate";
import "react-transliterate/dist/index.css";

import Input from "@material-ui/core/Input";

const App = () => {
  const [text, setText] = useState("");
  const [lang, setLang] = useState<Language>("hi");

  return (
    <ReactTransliterate
      renderComponent={(props) => {
        const inputRef = props.ref;
        delete props["ref"];
        return <Input {...props} inputRef={inputRef} />;
      }}
      value={text}
      onChangeText={(text) => {
        setText(text);
      }}
      lang={lang}
    />
  );
};

export default App;

Custom trigger keys

Keys which when pressed, input the current selection to the textbox

React Transliterate uses the event.keycode property to detect keys. Here are some predefined keys you can use. Or, you can enter the integer codes for any other key you'd like to use as the trigger

import React, { useState } from "react";

import { ReactTransliterate, TriggerKeys } from "react-transliterate";
import "react-transliterate/dist/index.css";

import Input from "@material-ui/core/Input";

const App = () => {
  const [text, setText] = useState("");

  return (
    <ReactTransliterate
      value={text}
      onChangeText={(text) => {
        setText(text);
      }}
      lang="hi"
      triggerKeys={[
        TriggerKeys.KEY_RETURN,
        TriggerKeys.KEY_ENTER,
        TriggerKeys.KEY_SPACE,
        TriggerKeys.KEY_TAB,
      ]}
    />
  );
};

export default App;

Get transliteration suggestions

import { getTransliterateSuggestions } from "react-transliterate";

const data = await getTransliterateSuggestions(
  word, // word to fetch suggestions for
  {
    numOptions: 5, // number of suggestions to fetch
    showCurrentWordAsLastSuggestion: true, // add the word as the last suggestion
    lang: "hi", // target language
  },
);

For a full example, take a look at the example folder

Props

Prop Required? Default Description
onChangeText Yes Listener for the current value from the component. (text: string) => void
value Yes value prop to pass to the component
enabled true Control whether suggestions should be shown
renderComponent (props) => <input {...props} /> Component to render. You can pass components from your component library as this prop
lang hi Language you want to transliterate. See the following section for language codes
maxOptions 5 Maximum number of suggestions to show in helper
offsetY 0 Extra space between the top of the helper and bottom of the caret
offsetX 0 Extra space between the caret and left of the helper
containerClassName empty string Classname passed to the container of the component
containerStyles {} CSS styles object passed to the container
activeItemStyles {} CSS styles object passed to the active item <li> tag
hideSuggestionBoxOnMobileDevices false Should the suggestions be visible on mobile devices since keyboards like Gboard and Swiftkey support typing in multiple languages
hideSuggestionBoxBreakpoint 450 type: number. To be used when hideSuggestionBoxOnMobileDevices is true. Suggestion box will not be shown below this device width
triggerKeys KEY_SPACE, KEY_ENTER, KEY_TAB, KEY_RETURN Keys which when pressed, input the current selection to the textbox
insertCurrentSelectionOnBlur true Should the current selection be inserted when blur event occurs
showCurrentWordAsLastSuggestion true Show current input as the last option in the suggestion box

Supported Languages

Language Code
Amharic am
Arabic ar
Bangla bn
Belarusian be
Bulgarian bg
Chinese (Hong Kong) yue-hant
Chinese (Simplified) zh
Chinese (Traditional) zh-hant
French fr
German de
Greek el
Gujarati gu
Hebrew he
Hindi hi
Italian it
Japanese ja
Kannada kn
Malayalam ml
Marathi mr
Nepali ne
Odia or
Persian fa
Portuguese (Brazil) pt
Punjabi pa
Russian ru
Sanskrit sa
Serbian sr
Sinhala si
Spanish es
Tamil ta
Telugu te
Tigrinya ti
Ukrainian uk
Urdu ur
Vietnamese vi

License

MIT © burhanuday

More Repositories

1

invoice-scanner-react-native

Solution for Problem 1 by team codesquad for AIDL 2020. Uses ML Kit for OCR and OpenCV for image processing
Java
132
star
2

SPAMit-WhatsApp-Spammer

SPAMit is an open source spammer for WhatsApp messenger that disguises itself as a keyboard allowing users to send hundreds of messages at the press of a button
Java
37
star
3

cors-proxy

JavaScript
24
star
4

razorsharp

Figma plugin to generate code from designs made in Blade
TypeScript
23
star
5

electron-react-boilerplate

Electron and Create React App boilerplate without any complex setup
JavaScript
22
star
6

miny

miny is a decluttered launcher for Android
Java
19
star
7

talk-easy

People face language barriers when it comes to the conference meetings around the globe. TalkEasy allows them to communicate in their own languages.
JavaScript
14
star
8

course-search

Find courses from multiple sources available to download in torrent form
JavaScript
11
star
9

Spam-em

Open source text spammer for Android
Java
8
star
10

topical

A topic based cross platform chat application built with React Native and Firebase
JavaScript
7
star
11

ML-DL-Algorithms

Repository containing notes, cheatsheets, datasets and usage of different ML and DL algorithms and libraries. These files can be used as base templates for your next project
Python
7
star
12

WordPress-Blog-App-Using-RxJava-Retrofit-Butterknife

A Medium themed example front end for the blog AndroidHive. Simply change the URL to make your own Android app for your wordpress site
Java
5
star
13

flutter-ecommerce

Dart
5
star
14

help-flare

Help Flare is a project aimed at reducing problems created by the COVID-19 lock-down. Report areas on a map that need help.
TypeScript
4
star
15

text-shorten

JavaScript
3
star
16

indic-type-chrome-extension

Chrome extension to type in 30+ languages using a standard keyboard
JavaScript
3
star
17

WhatsApp-Crasher

Crash WhatsApp messenger using a string which when clicked crashes the app
Java
3
star
18

burhanuday

2
star
19

csi-registration-app

Java
2
star
20

Blockchain-Bootcamp

JavaScript
2
star
21

github-jobs

Show jobs from Github using the Jobs API. Built with React, Typescript and styled-components
TypeScript
2
star
22

web-tidbits

CSS
2
star
23

ruby-rails

My notes while learning Ruby and RoR
Ruby
2
star
24

expo-boilerplate

A highly opinionated boilerplate for React Native Expo apps. Aimed at to be used in quickly prototyping projects without having to setup new codebases everytime!
JavaScript
2
star
25

renaissance-19-android-workshop

Java
2
star
26

network-builder

Cross platform app to get links to invitations for communities on WhatsApp, Discord, Telegram, Slack, Reddit and many others!
TypeScript
2
star
27

Blank-Message-for-WhatsApp

Send a blank message on WhatsApp Messenger
1
star
28

yarn-workspaces-monorepo

TypeScript
1
star
29

react-library-parcel

React library boilerplate bundled with Parcel v2
TypeScript
1
star
30

stylish

A clone of styled-components for a blog post. Not for actual use
JavaScript
1
star
31

theatre-booking-system

PHP
1
star
32

react-animations

JavaScript
1
star
33

Burger-App-With-React

JavaScript
1
star
34

Cemently-Cement-Reminder-App

An Android to-do reminder app that uses Alarm Manager and shows notification. Also uses SQLite to store data in the backend
Java
1
star
35

Data-Structures-And-Algorithms-in-Javascript

JavaScript
1
star
36

Pothole-GO

Java
1
star
37

agrishare

JavaScript
1
star
38

blog-app-with-microservices

A basic blog app to grasp the basics of micro-services by making my own implementation of the event bus
JavaScript
1
star
39

myntra-store

JavaScript
1
star
40

Car-Parking-Slot-Tracker

Kotlin
1
star
41

images

static hosting for images used for my blog
1
star
42

instagram-redesign-react-native

Redesigning Instagram in React Native
JavaScript
1
star
43

complaint-system

Python
1
star
44

ticketing-app

Ticketing app built with a microservice architecture. Uses Typescript, React, NextJS, Node, MongoDB, Jest, Docker and Kubernetes
TypeScript
1
star
45

optimal-page-replacement-algorithm-visualisation

JavaScript
1
star