Seite 1 von 1

Übersetzungsprogramm

Verfasst: 14.12.2010 15:58
von Raphi
HI Leute,

ich möchte so eine Art übersetzungs programm machen.

Nun weiß ich aber nicht wie ich zb den Text "Hallo ich bin das Übersetzungsprogramm"

in einen anderen Text zb. "Hello I am a translator"

dabei soll jedes wort einzeln übersetz werden zB. "Hallo" in "Hello"; "ich" in "I" usw.

kann mir jemand sagen welchen befehl ich benutzen soll, bzw wie man so was macht??

mfg Raphi

Re: Übersetzungsprogramm

Verfasst: 14.12.2010 16:02
von TomS
ReplaceString().
Allerdings wird das eine eher bescheidene Übersetzung, wenn du jedes Wort einzeln übersetzt.

Re: Übersetzungsprogramm

Verfasst: 14.12.2010 16:16
von ts-soft
FindString : ReplaceString

Das wird aber ein recht dürftiges Ergebnis und ziemlich langsam.

Mithilfe von Google kannste folgenden Code nutzen.
Vom Ergebnis sind aber noch ein paar Teile wegzufiltern :wink:

Code: Alles auswählen

InitNetwork()

CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
  Procedure.s MakeGUID()
    Protected guid.GUID, lpsz.s{76}
    If CoCreateGuid_(@guid) = #S_OK
      ProcedureReturn PeekS(@lpsz, StringFromGUID2_(guid, @lpsz, 76), #PB_Unicode)
    EndIf
  EndProcedure
CompilerCase #PB_OS_Linux
  Structure uuid_t
    char.b[16]
  EndStructure
  
  ImportC "-luuid"
    uuid_generate(*out.uuid_t)
    uuid_unparse_upper(*uu.uuid_t, *out)
  EndImport
  Procedure.s MakeGUID()
    ; thanks to freak
    Protected UUID$ = Space(36)
    Protected uuid.uuid_t
    uuid_generate(@uuid)
    uuid_unparse_upper(@uuid, @UUID$)
    UUID$ = "{" + UUID$ + "}"
    ProcedureReturn UUID$
  EndProcedure
CompilerCase #PB_OS_MacOS
  Procedure.s MakeGUID()
    ; only a simple workaround, you should implement a better solution,
    ; but i have no mac to test anything
    Protected result.s, i
    For i = 1 To 36
      result + Chr(Random(25) + 65)
    Next
    ProcedureReturn result
  EndProcedure
CompilerEndSelect
Procedure.s RemoveSigns(text.s)
  Protected *cText.Character = @text
  Protected result.s
  While *cText\c <> 0
    Select *cText\c
      Case '#', '%', '&', '{', '}', '|', 39, '/', '\'
        result + " "
      Default
        result + Chr(*cText\c)
    EndSelect
    *cText + SizeOf(Character)
  Wend

  ProcedureReturn result
EndProcedure

Procedure.s Translate(sText.s, sLang.s, dLang.s)
  ; thanks to kiffi
  sText = RemoveSigns(sText)
  Protected URL.s = URLEncoder("http://translate.google.com/translate_t?langpair=" + sLang + "|" + dLang + "&text=" + sText )
  Protected FF, Size, *mem, FileContent.s, P1, P2, result.s
  Protected TempFile.s = GetTemporaryDirectory() + MakeGUID()

  If ReceiveHTTPFile(URL, TempFile)
    FF = ReadFile(#PB_Any, TempFile)
    If FF
      Size = Lof(FF)
      *mem = AllocateMemory(Size)
      If *mem
        ReadData(FF, *mem, Size)
        FileContent = PeekS(*mem, Size, #PB_Ascii)
        FreeMemory(*mem)
        P1 = FindString(FileContent, "id=result_box", 1)
        If P1
          P1 = FindString(FileContent, ">", P1)
          If P1
            P1 + 1
            P2 = FindString(FileContent, "</div>", P1)
            If P2
              result = Mid(FileContent, P1, P2 - P1)
            EndIf
          EndIf
        EndIf
      EndIf
      CloseFile(FF)
    EndIf
    DeleteFile(TempFile)
  EndIf
  ProcedureReturn result
EndProcedure

Debug Translate("Hallo ich bin das Übersetzungsprogramm", "de", "en")
Mit einzelnen Wörtern funktioniert es besser.

Gruß
Thomas

Re: Übersetzungsprogramm

Verfasst: 14.12.2010 16:17
von Kiffi

Code: Alles auswählen

NewMap TranslateMap.s()

TranslateMap("Hallo")                = "Hello"
TranslateMap("ich")                  = "I"
TranslateMap("bin")                  = "am"
TranslateMap("das")                  = "a"
TranslateMap("Übersetzungsprogramm") = "translator"

German.s = "Hallo ich bin das Übersetzungsprogramm"

For Counter = 1 To CountString(German, " ") + 1
  Debug TranslateMap(StringField(German, Counter, " "))
Next
(kicher)

Grüße ... Kiffi

Re: Übersetzungsprogramm

Verfasst: 14.12.2010 16:45
von Raphi
Vielen dank erstmal :allright:

Es soll ja nicht wirklich ein Übersetztungsprogramm werden, das war nur als Beispiel gedacht weil das programm zb. Texte verschlüsseln soll ^^

Edit:

ReplaceString() war das was ich gebraucht habe.

Danke TomS :bounce: