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
Übersetzungsprogramm
Re: Übersetzungsprogramm
ReplaceString().
Allerdings wird das eine eher bescheidene Übersetzung, wenn du jedes Wort einzeln übersetzt.
Allerdings wird das eine eher bescheidene Übersetzung, wenn du jedes Wort einzeln übersetzt.
- ts-soft
- Beiträge: 22292
- Registriert: 08.09.2004 00:57
- Computerausstattung: Mainboard: MSI 970A-G43
CPU: AMD FX-6300 Six-Core Processor
GraKa: GeForce GTX 750 Ti, 2 GB
Memory: 16 GB DDR3-1600 - Dual Channel - Wohnort: Berlin
Re: Übersetzungsprogramm
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
Mit einzelnen Wörtern funktioniert es besser.
Gruß
Thomas
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

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")
Gruß
Thomas
Zuletzt geändert von ts-soft am 14.12.2010 16:18, insgesamt 1-mal geändert.
PureBasic 5.73 LTS | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Nutella hat nur sehr wenig Vitamine. Deswegen muss man davon relativ viel essen.

Nutella hat nur sehr wenig Vitamine. Deswegen muss man davon relativ viel essen.

Re: Übersetzungsprogramm
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
Grüße ... Kiffi
a²+b²=mc²
-
- Beiträge: 175
- Registriert: 06.08.2009 16:32
- Computerausstattung: Intel Core 2 Duo Processor (2 x 3 Ghz), ATI Radeon HD 4870 (512 MB), 4 GB DDR-2 Ram, Microsoft Windows 7 Ultimate, MBox 2 Mini Soundkarte
Re: Übersetzungsprogramm
Vielen dank erstmal
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

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
