Extapolate text from software?

Discussion in 'Rebol' started by MaxV, Jul 29, 2010.

  1. MaxV

    MaxV Member

    Good morning Rebolers,
    I need an help to get a simple way to translate to english the text of software.
    I'm italian, and obviously my software is first written with italian language (buttons, texts, and so on ...) then I rewrite it with in English.
    Is there a way to extrapolate text form rebol file?
    Usually all the texts are between " " (examle: "hello world!"), is there a way with parse or find or something else?
    Any idea is welcome
  2. Graham

    Graham Developer Staff Member

    Well, Rebol code has values such as string!, date!, function! etc.

    So, all you need to do is load your program and examine those values. If you find string! values, they are a good candidate for translation ...

    Have a look at Carl's color-code script on rebol.org which examines the value of each word in a script and assigns a color based on its datatype!
  3. notchent

    notchent Member

    MaxV, here's a quickie that may be useful:

    Code:
    rebol []
    code: {
        view layout [
            btn "some text"
            btn "some more text"
        ] 
    }
    strings: copy []
    parse code [any [thru {"} copy a-string to {"} (append strings a-string)] to end]
    foreach str strings [
        if true = request rejoin [{Change "} str {"?}] [
            replace/all code str request-text/title rejoin [{Change "} str {" to:}]
        ]
    ]
    editor code
    
    This will obviously work better if you use opening and closing curly braces instead of quotes to represent strings in your code.
  4. MaxV

    MaxV Member

    Very good, I added a check for corrected ", so I obtain only the real strings: ;)

    Code:
    code: { 
        view layout [
            btn "some text"
            btn "some more text"
        ] 
    }
    strings: copy []
    test: 1
    parse code [
       any [
          thru {"} (test: test + 1)   copy a-string
          to {"}  (if ((remainder test  2 ) = 0) [append strings a-string]) 
          ] 
        to end]
    parse code [any [thru "{"  copy a-string to "}" (append strings a-string) ] to end]
    probe strings
    alert "Done!"
    
    Now may next step is: how to use google translator with these strings?:cool:
    I can read the page of the translation simply with my browser, example: I want tor translate "Ciao mondo"
    Code:
    http://translate.google.com/?hl=it#auto|en|Ciao mondo
    
    but I can't read anywhere "Hello world" in source code of HTML, any suggestion?
    Thank you and best regards
    Max
  5. Graham

    Graham Developer Staff Member

    Must be being generated in Javascript so that's why you can't see it.
  6. MaxV

    MaxV Member

    I found that to substitute the strings, it's fundamental use mold.
    Without mold, "Hello" could be:
    • "Hello"
    • {Hello}

    with mold i obtain: {"Hello"} or {{Hello}}

    so the correct script is:

    Code:
    theurl: to-file request-file
    code: read/string  theurl
    strings: copy []
    test: 1
    parse code [
       any [
          thru {"} (test: test + 1)   copy a-string
          to {"}  (if ((remainder test  2 ) = 0) [append strings mold a-string]) 
          ] 
        to end]
    parse code [any [thru "{"  copy a-string to "}" (append strings mold a-string) ] to end]
    append  theurl  ".txt"
    sort strings
    strings: unique/case strings
    write theurl ""  ; clean file
    foreach temp strings [
    	write/append theurl {[ }	
    	write/append theurl (mold temp)
    	write/append theurl { ]}
    	write/append theurl "^/"
    	]
    alert "Done!"
    
  7. swhite

    swhite Member

    I once wrote a small program where I tried out the idea of putting ALL text (that is, button values, messages, EVERYTHING) into one file. I still have the code if you would like to examine it, but it is too big to paste into this message. The idea behind this was that if I wanted to translate the program to another language, I would have to translate just that one file. I never thought of using something like google to do the translating.

    Because all the text strings were identified by words, it would be possible to write a program to get each text string, although what one would DO with each text string, I have no idea.
  8. Graham

    Graham Developer Staff Member

    If you build your application with RebGUI, you get language localization built in.

Share This Page