FoxPro、谷歌翻译和 Unicode [英] FoxPro, Google Translate, and Unicode

查看:47
本文介绍了FoxPro、谷歌翻译和 Unicode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近接到的任务是编写一段 FoxPro 以与 Google 翻译交互,以便我们可以将软件中的文本翻译成当前用户/机器的语言.

I have recently been given the task of writing a piece of FoxPro to interface with Google Translate so we can translate text in our software to the language of the current user/machine.

我发现/修改/编写的代码非常适合基于拉丁语的字符集,但是如果你尝试像中文这样的东西,它会回来所有的问号.

The code I have found/modified/written works perfectly for Latin-based character sets, but if you try something like Chinese it comes back all question marks.

我已经尝试将 VFP 函数 STRCONV() 与所有可能的选项组合一起使用,但没有成功.我还尝试在以任何方式操作文本之前设置 LocaleID - 仍然没有运气.

I have already tried using the VFP function STRCONV() with every option combination possible, but no success. I also tried setting the LocaleID before the text is manipulated in any way--still no luck.

在这一点上,我没有想法.作为一个老 DOS 程序员,我几乎没有处理 unicode 的经验.

At this point, I am out of ideas. Being an old DOS programmer, I have little to no experience in dealing with unicode.

我没有包含任何代码,因为正如我所说,除非您尝试将其与中文(或日文)一起使用,否则代码可以正常工作.

I have not included any code, because as I said, the code works fine unless you try to use it with Chinese (or Japanese).

请帮忙!

这是与谷歌通信的功能.还有其他支持函数,但它们与编码无关.

This is the function which does the communication with google. There are other support functions, but they dont have to do with the encoding.

*   MODIFIED BY: MICHAEL COOLEY - 11/19/2012
*   PURPOSE: TRANSLATE TEXT FROM ONE LANGUAGE TO ANOTHER
*   EXPECTS: STRING (SOURCE LANGUAGE CODE)
*            STRING (DESTINATION LANGUAGE CODE)
*            STRING (THE TEXT TO TRANSLATE)
*   RETURNS: 
FUNCTION Translate(lcFrom,lcTo,lcText)
    LOCAL lcHttp AS MSXML2.XMLHTTP
    LOCAL lcRequest AS String

    lcRequest = "http://translate.google.com/translate_a/t?client=j" + ;
                "&"+"text="+this.EncodeURL(lcText)+"&"+"hl="+lcTo+"&"+"sl="+lcFrom+"&"+"tl="+lcTo

    lcHttp = CREATEOBJECT("MSXML2.XMLHTTP")
    lcHttp.open("GET",lcRequest,.f.)

    IF lcHttp.status == 200
        lcText = this.GetTranslationString("trans", lcHttp.responseText) + CHR(10)
    ELSE
        lcText = ""
    ENDIF

    RETURN lcText
ENDFUNC

推荐答案

Unicode 问题在 VFP 中并不新鲜,我建议阅读 Rick Strahl 的这篇文章:

The Unicode issue is not new in VFP, I suggest read this article from Rick Strahl:

--- 在 Visual FoxPro Web 和桌面应用程序中使用 Unicode ---

--- Using Unicode in Visual FoxPro Web and Desktop Applications ---

http://www.west-wind.com/presentations/foxunicode/foxunicode.asp

在本文中,我描述了如何将 Unicode 与您的支持多语言环境下的应用同时.虽然 Visual FoxPro 不能直接显示 Unicode,它可以通过使用 CodePages 来显示不同的字符集——一个特定于语言环境的字符映射 - VFP 很容易支持.这个适用于仅显示单个内容的应用程序语言/地区.但是如果您需要,这种方法有严重的局限性同时显示多种语言的字符串.我开始概述了问题以及如何使用 Unicode一般,然后向您展示如何检索和更新 Unicode 数据,以及最后,向您展示如何让 Unicode 内容同时显示在您的网络和桌面用户界面

In this article, I describe how you can use Unicode with your application in the context of supporting multiple languages simultaneously. Although Visual FoxPro can’t display Unicode directly, it can display different character set through use of CodePages – a locale specific character mapping - which VFP readily supports. This works well for applications that display content only from a single language/locale. But this approach has serious limitations if you need to display strings from multiple languages simultaneously. I start with an overview of the issues and how to work with Unicode in general, then show you how to retrieve and update Unicode data, and finally, show you how to get the Unicode content to display both in your Web and desktop user interfaces

这篇关于FoxPro、谷歌翻译和 Unicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆