string format (??) confusion

BlitzMax Forums/BlitzMax Programming/string format (??) confusion

That would be the only way I know how to convert text in BlitzMax

You wanna learn how UTF-8 works then :-)

By default Max strings are encoding in ISO 8859-1. Which is fine if you are using English, since it falls below ASCII 128. After that, you'll need to convert your ISO 8859-1 into UTF-8... and also url-encode the resultant conversion, since it is unlikely now to be valid ASCII (in the sense of what a URL expects to be valid)

Now, since it's you... ;-)
Function _textConvertMaxToUTF8:String(text:String)
	If Not text Then
		Return ""
	End If
	
	Local l:Int = text.length
	If l = 0 Then
		Return ""
	End If
	
	Local count:Int = 0
	Local s:Byte[] = New Byte[l * 3] ' max possible is 3 x original size.
	
	For Local i:Int = 0 Until l
		Local char:Int = text[i]

		If char < 128 Then
			s[count] = char
			count:+ 1
			Continue
		Else If char<2048
			s[count] = char/64 | 192
			count:+ 1
			s[count] = char Mod 64 | 128
			count:+ 1
			Continue
		Else
			s[count] =  char/4096 | 224
			count:+ 1
			s[count] = char/64 Mod 64 | 128
			count:+ 1
			s[count] = char Mod 64 | 128
			count:+ 1
			Continue
		EndIf
		
	Next

	Return String.fromBytes(s, count)
End Function


That will encode your string into UTF-8.

Note, you *only* want to encode the text you are translating..

Next up, you now run that through everyone's favourite url-encoder :
curl.Escape()


So, an example might look like :
Local trans:String = "<hello world in greek>"
trans = curl.escape(_textConvertMaxToUTF8(trans))

Local s:String = "ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=" + trans + "&langpair=el%7Cen"

curl.setOptString(CURLOPT_URL, s)


As for the referrer : "Applications MUST always include a valid and accurate http referer header in their requests."
I have no idea what it is meant to be... perhaps the address of your module page? *shrug*

:o)