how can i write Arabic in app engine

67 views
Skip to first unread message

tota

unread,
Dec 14, 2010, 6:33:47 PM12/14/10
to Google App Engine
Hi
I have an application in google app engine and i want to make the
interface langauge in Arabic. I tried to do that but it display in
undefined charecters. I am using python. can any one help me.
Thanks

风笑雪

unread,
Dec 15, 2010, 12:41:12 PM12/15/10
to google-a...@googlegroups.com
Hi, I don't know what framework are your using.

Generally speaking, you should set "Content-Type:text/html; charset=UTF-8" header, and make sure you output UTF-8 encoded sting.

If you are using webapp, it will look like this:

self.response.headers['Content-Type'] = 'Content-Type:text/html; charset=UTF-8'
self.response.out.write(u'something in Arabic'.encode('utf-8'))

----------
keakon

My blog(Chinese): www.keakon.net

fatimah mujallid

unread,
Dec 15, 2010, 6:22:59 PM12/15/10
to google-a...@googlegroups.com
Hi,thank you for your replay
I have this code in main.py
----
class Whatisinyourmind (db.Model):
    name=db.StringProperty()
    yourword=db.StringProperty()
   
class MainHandler(webapp.RequestHandler):
    def get(self):
        yourwords=db.GqlQuery('SELECT * FROM Whatisinyourmind')
        values={'yourwords':yourwords}
        self.response.out.write(template.render('main.html',values).decode('windows-1256'))
    def post(self):
        whatisinyourmind=Whatisinyourmind()
        nameTemp=self.request.get('name')
        #nameTemp=unicode(nameTemp,'windows-1256')
        whatisinyourmind.name=nameTemp  
        temp=self.request.get('yourword')
        #temp=unicode(temp,'windows-1256')
        whatisinyourmind.yourword=temp  
        whatisinyourmind.put()
        self.redirect('/')
-----------
you can see from the above code i used decode() to display any Arabic characters and it display will EXCEPT the Arabic characters that i retrieve it from the database it display garbish
The code in main.html are
----------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256">
    <title>Untitled Page</title>
</head>
<body>
  <h1>ماذا يدور في عقلك؟</h1>
  <form action="" method="post" accept-charset="windows-1256">
   {% for yourword in yourwords %}
    <div>{{yourword.name}}</>
    <div>{{yourword.yourword}}</>
   {% endfor %}
  <br>
  <label>الإسم الكريم: </label>
  <input id="name" type="text"  name="name"/>
  <label>الكلمة:</label>
  <input id="yourword" type="text"  name="yourword"/>
  <input id="button1" type="submit" value="Post" />
 </form>     
</body>
</html>
------------------
thanks again
2010/12/15 风笑雪 <kea...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To post to this group, send email to google-a...@googlegroups.com.
To unsubscribe from this group, send email to google-appengi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.

风笑雪

unread,
Dec 16, 2010, 6:02:05 AM12/16/10
to google-a...@googlegroups.com
I suggest you always use UTF-8, not windows-1256.

However, if you insist on using windows-1256, you should encode your unicode output to str:
self.response.out.write(u'some unicode string'.encode('windows-1256'))
or:
self.response.out.write('some windows-1256 string') # don't decode it

fatimah mujallid

unread,
Dec 16, 2010, 5:10:54 PM12/16/10
to google-a...@googlegroups.com
Ok this code works great:
self.response.out.write(u'السلام عليكم'.encode('utf-8'))
but when i use an html page instead of a string just like this:
self.response.out.write(template.render(u'test.html'.encode('utf-8')))
it displays arabic characters rabish
in the html page i tried to write this:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
and tried with out it arabic characters rabish
both displays
2010/12/16 风笑雪 <kea...@gmail.com>
--

fatimah mujallid

unread,
Dec 16, 2010, 5:11:51 PM12/16/10
to google-a...@googlegroups.com
Ok this code works great:
self.response.out.write(u'
السلام عليكم'.encode('utf-8'))
but when i use an html page instead of a string just like this:
self.response.out.write(template.render(u'test.html'.encode('utf-8')))
it displays arabic characters rabish
in the html page i tried to write this:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
and tried with out it
both displays arabic characters rabish


2010/12/17 fatimah mujallid <f.muj...@gmail.com>

Geoffrey Spear

unread,
Dec 17, 2010, 1:39:33 PM12/17/10
to Google App Engine
You're just encoding the filename in utf-8 (which is identical to its
ASCII encoding as it doesn't comain non-ASCII characters) and then
passing that encoded filename to django's template engine.)

On Dec 16, 5:11 pm, fatimah mujallid <f.mujal...@gmail.com> wrote:
> Ok this code works great:
> self.response.out.write(u'
> السلام عليكم'.encode('utf-8'))
> but when i use an html page instead of a string just like this:
> self.response.out.write(template.render(u'test.html'.encode('utf-8')))
> it displays arabic characters rabish
> in the html page i tried to write this:
> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
> and tried with out it
> both displays arabic characters rabish
>
> 2010/12/17 fatimah mujallid <f.mujal...@gmail.com>
>
>
>
>
>
>
>
> > Ok this code works great:
> > self.response.out.write(u'السلام عليكم'.encode('utf-8'))
> > but when i use an html page instead of a string just like this:
> > self.response.out.write(template.render(u'test.html'.encode('utf-8')))
> > it displays arabic characters rabish
> > in the html page i tried to write this:
> > <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
> > and tried with out it arabic characters rabish
> > both displays
> > 2010/12/16 风笑雪 <kea...@gmail.com>
>
> > I suggest you always use UTF-8, not windows-1256.
>
> >> However, if you insist on using windows-1256, you should encode your
> >> unicode output to str:
> >> self.response.out.write(u'some unicode string'.*encode*('windows-1256'))
> >> or:
> >> self.response.out.write('some windows-1256 string') # don't decode it
>
> >> ----------
> >> keakon
>
> >> My blog(Chinese):www.keakon.net
> >> Blog source code:https://bitbucket.org/keakon/doodle/
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Google App Engine" group.
> >> To post to this group, send email to google-a...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> google-appengi...@googlegroups.com<google-appengine%2Bunsubscrib e...@googlegroups.com>
> >> .

fatimah mujallid

unread,
Dec 17, 2010, 6:05:24 PM12/17/10
to google-a...@googlegroups.com
Finally it works perfect
Thank you all for replying and you support

2010/12/17 Geoffrey Spear <geoff...@gmail.com>
To unsubscribe from this group, send email to google-appengi...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages