Skip to content

Commit

Permalink
Merge pull request #13 from kartikvirendrar/master
Browse files Browse the repository at this point in the history
added transliteration logging part for custom api
  • Loading branch information
ishvindersethi22 authored Jul 2, 2024
2 parents ca9ff9f + c209066 commit 1b7ae21
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ai4bharat/indic-transliterate",
"version": "1.3.2",
"version": "1.3.3",
"description": "Transliterate component for React",
"author": "AI4Bharat",
"license": "MIT",
Expand Down
1 change: 1 addition & 0 deletions src/constants/Urls.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const BASE_URL = "https://xlit-api.ai4bharat.org/";
export const BASE_URL_TL = "https://xlit-api.ai4bharat.org/tl/";
4 changes: 3 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { LangObject } from "./types/LangObject";
import { TriggerKeys } from "./constants/TriggerKeys";
import { getTransliterateSuggestions } from "./util/suggestions-util";
import { getTransliterationLanguages } from "./util/getTransliterationLanguages";
import { BASE_URL_TL } from "./constants/Urls";

const KEY_UP = "ArrowUp";
const KEY_DOWN = "ArrowDown";
Expand Down Expand Up @@ -44,6 +45,7 @@ export const IndicTransliterate = ({
showCurrentWordAsLastSuggestion = true,
enabled = true,
horizontalView = false,
customApiURL = BASE_URL_TL,
...rest
}: IndicTransliterateProps): JSX.Element => {
interface LogJson {
Expand Down Expand Up @@ -137,7 +139,7 @@ export const IndicTransliterate = ({
? maxOptions - 1
: maxOptions;

const data = await getTransliterateSuggestions(lastWord, {
const data = await getTransliterateSuggestions(lastWord, customApiURL, {
numOptions,
showCurrentWordAsLastSuggestion,
lang,
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/Props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,6 @@ export interface IndicTransliterateProps
* @type boolean
*/
horizontalView?: boolean;

customApiURL?: string;
}
13 changes: 8 additions & 5 deletions src/util/suggestions-util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Language } from "../types/Language";
import { BASE_URL } from "../constants/Urls";

type Config = {
numOptions?: number;
Expand All @@ -9,6 +8,7 @@ type Config = {

export const getTransliterateSuggestions = async (
word: string,
customApiURL: string,
config?: Config,
): Promise<string[] | undefined> => {
const { showCurrentWordAsLastSuggestion, lang } = config || {
Expand All @@ -27,16 +27,19 @@ export const getTransliterateSuggestions = async (

try {
const res = await fetch(
BASE_URL +
`tl/${lang}/${
customApiURL +
`${lang}/${
word === "." || word === ".."
? " " + word.replace(".", "%2E")
: encodeURIComponent(word).replace(".", "%2E")
}`,
requestOptions,
);
const data = await res.json();
console.log("library data", data);
let data = await res.json();
console.log("library data", data);
if(!customApiURL.includes("xlit-api")){
data.result = data.output[0].target;
}
if (data && data.result.length > 0) {
const found = showCurrentWordAsLastSuggestion
? [...data.result, word]
Expand Down

0 comments on commit 1b7ae21

Please sign in to comment.