Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Google API for transliteration in VFP

Status
Not open for further replies.

Ris1

Programmer
Dec 8, 2017
26
IN
I want to use google API which transliterate from 1 language into another. Below is the link which describes about using API. But uses HTML and Java Script as explained in Example.

I want to use this API in VFP form so that user typing in english in a textbox get transliterated text in another text box.
I don't know from where to start with ?
 
You can't call the API directly from VFP. As the tutorial explains, you need to use Javascript.

If you want to create a VFP form, in which your user can type some text and see its transliteration, you could try this:

1. Copy the Hello World example from the tutorial into a text file. Save it on your computer with the extension HTM.

2. Create a VFP form. Drop an OLE Web Browser control onto it. Name it, say, oBrowser.

3. Put a button on the form. In its Click event, type [tt]THISFORM.oBrowser.Navigate2("c:\forms\hello.htm")[/tt], where [tt]c:\forms\hello.htm[/tt] is the name under which you saved the file.

4. When you run the form, the user will see a textbox into which they can type Hindi text, and see it transliterated into English (or vice versa).

The above isn't meant to be a complete solution. It's just to give you the general idea.

If you want to transliterate text automatically within your application, without user involvement, then that's more difficult.

Finally, note that transliteration isn't the same as translation. Google has a different set of tools for translation.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Yes, transliteration is different from translation. I want transliteration as I want Name and Address typed in English in another language. If I use Web Browser, then how will I get the transliterated text as string which I could save in database ?

 
That can be done, but without a deep understanding of JavaScript, you are going to find it very difficult.

I suggest you focus on getting it working in a web browser first - not in VFP. You could try asking for help in a JavaScript-related forum. If you do, don't mention VFP - it will only confuse them. Just concentrate on creating a web form (in HTML) that can interact with the API.

If you succeed in getting that working, come back here and we can discuss how to integrate it into a VFP application.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
There are probably other solutions that don't involve the Google API. Try searching for "How to transliterate English text into Hindi" (or Sanskrit, or Arabic, or whatever). You might find some software or services that are easier to use.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Yes, It is working fine in web browser . Code which I have written in the .html file is below

Code:
 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <script type="text/javascript" 
src="[URL unfurl="true"]https://www.google.com/jsapi">[/URL] </script> <script type="text/javascript"> // Load the Google Transliterate API 
google.load("elements", "1", { packages: "transliteration" }); function onLoad() { var options = { sourceLanguage: 
google.elements.transliteration.LanguageCode.ENGLISH, destinationLanguage: 
[google.elements.transliteration.LanguageCode.HINDI], shortcutKey: 'ctrl+g', transliterationEnabled: true }; // Create an instance on 
TransliterationControl with the required // options. var control = new google.elements.transliteration.TransliterationControl(options); // 
Enable transliteration in the textbox with id // 'transliterateTextarea'. 
control.makeTransliteratable(['transliterateTextarea']); } google.setOnLoadCallback(onLoad); </script> </head> <body> Type in 
Hindi (Press Ctrl+g to toggle between English and Hindi)<br> <textarea id="transliterateTextarea" style="width:600px;height:200px"></textarea>
 </body> </html>]

Now, I want converted string in VFP. Please check the html file attached for better view
 
Good to see you are making progress, but I don't think it's that simple. The FAQ you referenced shows how to create a form in which you can type some Javascript, which you can then have executed. That's a useful feature, but it doesn't solve your problem. You still need to know what Javascript to execute - an dhow to integrate it in your form.

But keep persevering. You might well be heading in the right direction.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Just going to
I first see:
The Google Transliterate API has been officially deprecated as of May 26, 2011. It will continue to work as per our deprecation policy.

You should look out for something that's not just in a prolonged deprecation phase, but current API for that feature. Even if what the demos show you
works for you, you're building on something, that might get switched off without replacement.

Bye, Olaf.
 
Hi

Not sure if these are of any help, but i cam across this when trying to integrate an HTML editor in our app:

[URL unfurl="true"]https://weblog.west-wind.com/posts/2008/Sep/27/Calling-JavaScript-functions-in-the-Web-Browser-Control[/url]

My discussion around it: [URL unfurl="true"]https://www.tek-tips.com/viewthread.cfm?qid=1752388[/url]

The point here is I had to get the entered text back into VFP to populate the database via Javascript. Might give you a pointer if nothing else :)

Regards
Neil

I like work. It fascinates me. I can sit and look at it for hours...
 
Text written in Hindi language in HTML textbox is in Unicode and as VFP doesn't support unicode, it gets replaced with ?? in VFP. Is there any way to
get data.

I have written a manual transliteration program which converts english words into Hindi but It is not that efficient .

I searched this but now a days , Keyboards supporting Hindi language are in unicode, so vfp doesn't displays text in hindi , it displays ? mark.


 
Did you find an ActiveX working in Unicode? Then try if SYS(3101,65001) helps you get the UNICODE converted as ANSI string when you read the text from a property of the control, eg loControl.Text or however the ActiveX control name is of the property with the display text in Hindi Unicode.

Bye, Olaf.
 
Yes, I found Microsoft Textbox 2.0 which displays Hindi text in unicode . I have declared 2 settings
sys(987,.F.)
sys(3101,65001)

But it is accepting input from Google input tools only and Inscript keyboard is displaying ?? mark . Is some other setting are required for that.
 
You're doing contrary things with SYS(987,.F.) and SYS(3101,65001). With SYS(987,.F.) you're NOT converting Unicode to ANSI, with SYS(3101,65001) you ARE. I gave that thinking you would want to store Ansi instead of Unicode into DBFs and after input with Google API would like to continue working in ANSI with VFP.

If you want to stay in the realm of Unicode, you can't use any VFP controls, have to use all Unicode ActiveX controls and when using SQL Server as your backend can use NCHAR/NVARCHAR columns.

What you need then is SYS(987,.F.) in combination with SYS(3101,0), no conversion.

And by the way, you also shouldn't mix Unicode with UTF-8, UTF-8 can encode almost all Unicode characters, but isn't the Unicode format the MS Office Textbox2.0 control needs.

You also need to use a Unicode capable font.

Bye, Olaf.
 
I don't know what is happening but what I observed is-
I have dropped Microsoft Form 2.0 Textbox on the form and in the form's init event added this - SYS(3101,65001)

Now, When I start typing with Devnagri Inscript keyboard, it displays ? mark(With google IME it displays in hindi fonts). When I type in Word Doc. and copy hindi text to activex, textbox displays correctly. I want to type with Devnagri Inscript keyboard in activex itself , so is there any additional setting for that.

Will it be possible to print unicode data in VFP

 
On one side, you should try SYS(3101,0) as already said. But on the other side, whatever you type or copy&paste directly into an ActiveX control only is governed by this control and the OS. VFP has nothing to do with that. Both the display of ActiveX controls and their rendering is in a completely own (borderless) form not handled by VFP at all, having its own HWND and so also all windows and keyboard and mouse events are not going to the VFP process but to the runtime of the OCX/DLL in whatever language the control is written in. And as it is Unicode capable, that's not VFPs runtime.

SYS(3101) is in effect when you read/write a property of the ActiveX control or call methods, not beforehand in interactive handling, neither with keyboard handling and buffer, nor with the clipboard.

Whatever problem you have with the interactive use of the ActiveX control on a VFP form is beyond me, I don't know what could cause this to render input as questionmark. Do you have any code in the control?

Bye, Olaf.

PS: There always is one setting for ActiveX: _vfp.autoyield. Try both .T. and .F., but it shouldn't change Unicode/Keyboard input handling.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top