|
Post by juppel on Mar 24, 2019 20:20:19 GMT 1
Hello My English is not so good. I hope the google translator translates everything correctly. I would like to introduce my project here. Maybe one or the other can do something with it. Maybe someone else has ideas?
These programs build an installer from the program code, which is translated in the respective language of the operating system. for this the bacon.sh is needed
First the texts are filtered out of the program code and stored in the file language.txt. Then you can remove some lines that should not be translated. Then copy the content into the google translator and translate it. Then insert the translation into the language.txt and work. Now just run ./build_installer yourProgram.bac and an install.sh is created.
if you do this, your program will automatically be translated into your language and compiled. Icons are created on the desktop
To translate your program you can also type ./translate your program.bac
Try it. Maybe you have any ideas to
build_installer.tar.gz (88.19 KB)
|
|
|
Post by Pjot on Mar 25, 2019 18:47:31 GMT 1
Hi juppel, Herzlich willkommen! Thanks for your contribution. It is an interesting concept. Would it be a good idea to automate the translation using a free online API? BR Peter
|
|
|
Post by juppel on Mar 26, 2019 19:49:10 GMT 1
Hello Peter, Thanks a lot! I like the idea, but how do you integrate an api in Basic so that I can translate a simple text? I also found translate-shell, which also seems to work well.
Further ideas 1. a GUI, on the left in a column the text to be translated appears, which serves as a jump marker. And the source text appears on the right. Then you can compare better, if you want to translate this or not! The source text then automatically jumps to the selected, filtered text passage (better would be the source code to be translated, basically with the INTL $ command to mark.) Maybe then you can also between the possibilities a po (mo) file for a translation or automatically translate the source code, choose)
2. then select the foreign languages and these should be translated automatically. 3. then also editable.
4. the whole then with automatic versioning. And built in BaconGui ;-)
|
|
|
Post by Pjot on Mar 26, 2019 21:14:25 GMT 1
but how do you integrate an api in Basic so that I can translate a simple text? Hi juppel, The Frengly API works pretty straightforward. First create a (free) account there. Then you need to construct a POST request and send JSON data to the URL (see the below code, which translates English to German). BR Peter CONST website$ = "frengly.com"
INPUT "Enter your English text: ", text$
json$ = "{" \ "\"src\":\"en\"," \ "\"dest\":\"de\"," \ "\"text\":\"" & text$ & "\"," \ "\"email\":\"yyyy@gmail.com\"," \ "\"password\":\"xxxx\"" \ "}"
req$ = "POST /frengly/data/translateREST HTTP/1.1\r\nHost: " & website$ & "\r\nContent-Type: application/json\r\nContent-Length: " & STR$(LEN(json$)) & "\r\n\r\n" & json$
OPEN website$ & ":80" FOR NETWORK AS mynet
SEND req$ TO mynet
RECEIVE data$ FROM mynet
FOR item$ IN data$ STEP "," IF TOKEN$(item$, 1, ":") = "\"translation\"" THEN PRINT TOKEN$(item$, 2, ":") NEXT
CLOSE NETWORK mynet
Sample output:
|
|
|
Post by juppel on Mar 26, 2019 22:10:14 GMT 1
thank you, it works then I will work!
|
|
|
Post by Pjot on Mar 27, 2019 19:31:13 GMT 1
Hi juppel, For what it is worth, you could also consider to use the DICT protocol to translate separate words. The advantage of this protocol is that you do not need any registration. There is a public DICT server at dict.org. Usually, a DICT server explains a word in the same language, like a normal dictionary. However, the dict.org server also is able to provide translations. The list they currently support: fd-tur-eng "Turkish-English FreeDict Dictionary ver. 0.2.1" fd-por-deu "Portuguese-German FreeDict Dictionary ver. 0.1.1" fd-nld-eng "Dutch-English Freedict Dictionary ver. 0.1.3" fd-eng-ara "English-Arabic FreeDict Dictionary ver. 0.6.2" fd-spa-eng "Spanish-English FreeDict Dictionary ver. 0.1.1" fd-eng-hun "English-Hungarian FreeDict Dictionary ver. 0.1" fd-ita-eng "Italian-English FreeDict Dictionary ver. 0.1.1" fd-wel-eng "Welsh-English Freedict dictionary" fd-eng-nld "English-Dutch FreeDict Dictionary ver. 0.1.1" fd-fra-eng "French-English FreeDict Dictionary ver. 0.3.4" fd-tur-deu "Turkish-German FreeDict Dictionary ver. 0.1.1" fd-swe-eng "Swedish-English FreeDict Dictionary ver. 0.1.1" fd-nld-fra "Nederlands-French FreeDict Dictionary ver. 0.1.1" fd-eng-swa "English-Swahili xFried/FreeDict Dictionary" fd-deu-nld "German-Dutch FreeDict Dictionary ver. 0.1.1" fd-fra-deu "French-German FreeDict Dictionary ver. 0.1.1" fd-eng-cro "English-Croatian Freedict Dictionary" fd-eng-ita "English-Italian FreeDict Dictionary ver. 0.1.1" fd-eng-lat "English-Latin FreeDict Dictionary ver. 0.1.1" fd-lat-eng "Latin-English FreeDict Dictionary ver. 0.1.1" fd-fra-nld "French-Dutch FreeDict Dictionary ver. 0.1.2" fd-ita-deu "Italian-German FreeDict Dictionary ver. 0.1.1" fd-eng-hin "English-Hindi FreeDict Dictionary ver. 1.5.1" fd-deu-eng "German-English FreeDict Dictionary ver. 0.3.4" fd-por-eng "Portuguese-English FreeDict Dictionary ver. 0.1.1" fd-lat-deu "Latin - German FreeDict dictionary ver. 0.4" fd-jpn-deu "Japanese-German FreeDict Dictionary ver. 0.1.1" fd-eng-deu "English-German FreeDict Dictionary ver. 0.3.6" fd-eng-scr "English-Serbo-Croat Freedict dictionary" fd-eng-rom "English-Romanian FreeDict Dictionary ver. 0.6.1" fd-iri-eng "Irish-English Freedict dictionary" fd-cze-eng "Czech-English Freedict dictionary" fd-scr-eng "Serbo-Croat-English Freedict dictionary" fd-eng-cze "English-Czech fdicts/FreeDict Dictionary" fd-eng-rus "English-Russian FreeDict Dictionary ver. 0.3" fd-afr-deu "Afrikaans-German FreeDict Dictionary ver. 0.3" fd-eng-por "English-Portuguese FreeDict Dictionary ver. 0.2.2" fd-hun-eng "Hungarian-English FreeDict Dictionary ver. 0.3.1" fd-eng-swe "English-Swedish FreeDict Dictionary ver. 0.1.1" fd-deu-ita "German-Italian FreeDict Dictionary ver. 0.1.1" fd-cro-eng "Croatian-English Freedict Dictionary" fd-dan-eng "Danish-English FreeDict Dictionary ver. 0.2.1" fd-eng-tur "English-Turkish FreeDict Dictionary ver. 0.2.1" fd-eng-spa "English-Spanish FreeDict Dictionary ver. 0.2.1" fd-nld-deu "Dutch-German FreeDict Dictionary ver. 0.1.1" fd-deu-por "German-Portuguese FreeDict Dictionary ver. 0.2.1" fd-swa-eng "Swahili-English xFried/FreeDict Dictionary" fd-hin-eng "English-Hindi Freedict Dictionary [reverse index]" fd-deu-fra "German-French FreeDict Dictionary ver. 0.3.1" fd-eng-fra "English-French FreeDict Dictionary ver. 0.1.4" fd-slo-eng "Slovak-English Freedict dictionary" fd-gla-deu "Scottish Gaelic-German FreeDict Dictionary ver. 0.1.1" fd-eng-wel "English-Welsh Freedict dictionary" fd-eng-iri "English-Irish Freedict dictionary"
So, to translate a word from English to German, we need to use the database called 'fd-eng-deu' (fd means Free Dictionary). According to RFC2229 we need to connect to dict.org using TCP port 2628 and then construct a DEFINE command. In BaCon, this could be done as follows: CONST website$ = "dict.org"
INPUT "Enter your English text: ", text$
req$ = "DEFINE fd-eng-deu " & text$ & CR$ & NL$
OPEN website$ & ":2628" FOR NETWORK AS mynet
SEND req$ TO mynet
REPEAT RECEIVE data$ FROM mynet total$ = total$ & data$ UNTIL NOT(WAIT(mynet, 1000))
SEND "QUIT" TO mynet
CLOSE NETWORK mynet
' Show result show = FALSE
FOR line$ IN total$ STEP NL$ IF show THEN IF NOT(REGEX(line$, "\\.$|" & text$)) THEN PRINT line$ BREAK ENDIF ELIF TOKEN$(line$, 1) = "550" THEN PRINT "Invalid database." BREAK ELIF TOKEN$(line$, 1) = "552" THEN PRINT "No match found." BREAK ELIF TOKEN$(line$, 1) = "151" THEN show = TRUE ENDIF NEXT
Sample run: Enter your English text: goodbye Auf Wiedersehen Enter your English text: house Haus <n> Enter your English text: memory Andenken <n>; Erinnerung <f>; Gedächtnis; Speicher (Computer) <m>
Best regards Peter
|
|
|
Post by juppel on Apr 27, 2019 15:24:33 GMT 1
Hello here again a small script, which translates the programs from foreign languages into the system language. There are still gaps in the translation, unfortunately I do not find the error. I use translate-shell for this. Because this works best. Try it
if you use /bin/bac you can let the programs translate in themselves:
#!/bin/bash bacon=/usr/local/bin/bacon fullpath=$(readlink -f "$1") echo $fullpath | tr -d "\n" >/tmp/mySourceFilePath tempbac=$(mktemp) cat "$fullpath" | egrep -v '^#!' > "$tempbac.bac" "$bacon" -ys "$tempbac.bac" > /dev/null shift "$tempbac" "$@" rm -f "$tempbac.bac" "$tempbac" "/tmp/mySourceFilePath"
many Greetings
'#!/bin/bac '------------------------------------------------------------------------------------------------------------------- CALL translatemyself 'Beginn Subroutins
SUB SourceTextFilter
letters$ = "ö ä ü Ö Ä Ü a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
SAVE "" TO langfile$ FOR var1$ IN file$ OPEN var1$ FOR READING AS myfile WHILE NOT(ENDFILE(myfile)) DO READLN fs$ FROM myfile fsline$ = "" 'exclude Filter$ = "IMPORT ALIAS EXEC$ SYSTEM" FOR var2$ IN Filter$ IF INSTR(fs$, var2$) THEN fs$ = "" BREAK END IF NEXT var2$ 'include Filter$ = " INTL$ PRINT Statusbar_Msg gtk_label_set_text title menu_item_new \ set_name append_text new_with tooltip_text Run_Dialog selection_dialog_new \ chooser_dialog_new GTK_BUTTONS_YES_NO gtk_label_new GTK_BUTTONS_CLOSE gtk_check_button_new_with_label \ gtk_frame_new Run_Dialog " FOR var2$ IN Filter$ IF INSTR(fs$, var2$) THEN fsline$ = fs$ BREAK END IF NEXT var2$
a = 0 b = 0 REPEAT altb = b IF INSTR(fsline$, CHR$(34), b + 1) THEN a = INSTR(fsline$, CHR$(34), b + 1) b = INSTR(fsline$, CHR$(34), a + 1) text$ = MID$(fsline$, a + 1, b - a - 1) END IF IF LEN(text$) > 2 AND b <> altb THEN l = 0 IF LEFT$(text$, 1) = " " THEN FOR i = 1 TO LEN(text$) IF MID$(text$, i, 1) <> " " THEN l = i - 1 BREAK END IF NEXT i END IF FOR var$ IN letters$ IF INSTR(text$, var$) THEN z = z + 1 line$ = STR$(z) 'im folgenden die Leerzeichen rechts im Text entfernen FOR i = LEN(text$) TO 1 STEP -1 IF MID$(text$, i, 1) <> " " THEN text$ = LEFT$(text$, i) i = 1 END IF NEXT i '----------------------------------------------------- APPEND "[" & line$ & " bac] = " & RIGHT$(text$, LEN(text$) - l) & CHR$(10) TO langfile$ BREAK END IF NEXT var$ END IF UNTIL b = altb WEND CLOSE FILE myfile NEXT var1$
show = FALSE
'trans can just 100 lines text$="" OPEN langfile$ FOR READING AS myfile WHILE NOT(ENDFILE(myfile)) DO READLN fs$ FROM myfile fs$ = REPLACE$(fs$, "_", "") text$ = text$ & fs$ & NL$ z=z+1 IF z>97 THEN z=0 SYSTEM "trans -brief " & CHR$(34) & text$ & CHR$(34) & " >>" & langfile$ & "." & language$ text$="" ENDIF WEND CLOSE FILE myfile SYSTEM "trans -brief " & CHR$(34) & text$ & CHR$(34) & " >>" & langfile$ & "." & language$
text$ = LOAD$(langfile$ & "." & language$) text$ = REPLACE$(text$, "bac]", language$ & "]") text$ = REPLACE$(text$, " " & CHR$(92) & " t", CHR$(92) & "t") text$ = REPLACE$(text$, " " & CHR$(92) & " N ", CHR$(92) & "n") text$ = REPLACE$(text$, CHR$(92) & " n", CHR$(92) & "n") text$ = REPLACE$(text$, CHR$(34), "'")
APPEND text$ TO langfile$ DELETE FILE langfile$ & "." & language$ PRINT "ready" END SUB
'-------------------------------------------------------------------------------------------------------------------
SUB translatemyself
language$ = TOKEN$(GETENVIRON$("LANG"), 1, "_")
'load the path of the Source File 'file$ = LOAD$("/tmp/mySourceFilePath") : REM for /bin/bac you need this
file$ = TOKEN$(ARGUMENT$, 2) : REM delete for /bin/bac
langfile$ = REPLACE$(file$, ".bac", ".lan")
IF FILEEXISTS(langfile$)=0 THEN CALL SourceTextFilter
'Test ist already translated? source$ = LOAD$(file$) IF INSTR(source$, CHR$(39) & "already translated") = 0 AND FILEEXISTS(langfile$) THEN '----------------------------------------------------- SAVE "" TO file$ & "." & language$ OPEN file$ FOR READING AS myfile WHILE NOT(ENDFILE(myfile)) DO READLN fsline$ FROM myfile text$="" OPEN langfile$ FOR READING AS myfile1 WHILE NOT(ENDFILE(myfile1)) DO READLN bac$ FROM myfile1 line$ = REPLACE$(bac$, "bac] = ", language$ & "] = ") languageline$ = LEFT$(line$, INSTR(line$, "] = ")) bac$ = RIGHT$(bac$, LEN(bac$) - INSTR(bac$, "] = ") - 3) IF INSTR(fsline$, bac$) THEN WHILE NOT(ENDFILE(myfile1)) DO READLN frgnlnguge$ FROM myfile1 IF INSTR(frgnlnguge$, languageline$) THEN frgnlnguge$ = RIGHT$(frgnlnguge$, LEN(frgnlnguge$) - INSTR(frgnlnguge$, "] = ") - 3) 'Wenn die Sprache mit der Zeile gefunden wird dann den Text übersetzen IF MID$(fsline$, INSTR(fsline$, bac$) - 1, 1) = CHR$(34) THEN text$ = REPLACE$(fsline$, bac$, frgnlnguge$) END IF GOTO isfound END IF WEND END IF WEND LABEL isfound CLOSE FILE myfile1 IF text$ <> "" THEN APPEND text$ & NL$ TO file$ & "." & language$ ELSE APPEND fsline$ & NL$ TO file$ & "." & language$ END IF WEND CLOSE FILE myfile
APPEND CHR$(39) & "already translated" & NL$ TO file$ & "." & language$ RENAME file$ & "." & language$ TO language$ & "_" & file$ : REM for /bin/bac delete (to language$ &) 'SYSTEM "chmod +x " & file$ : REM for /bin/bac you need this 'RUN file$ : REM for /bin/bac you need this END
ELSE IF FILEEXISTS(langfile$)=0 THEN PRINT "no language file found" ENDIF END SUB
|
|