[Zope] zope, wap and nationalities
Jaroslav Lukesh
lukesh at seznam.cz
Mon Jan 24 08:48:48 EST 2005
Dne pátek, 21. ledna 2005 10:45 Jaroslav Lukesh napsal(a):
> Do you have somebody tip for encoding national characters into wap?
>
> For example, character in latin-2 interpreted as "č" need to be interpreted
> in utf8 for wml as "č"
So here are solution, new zope tag :o). Simply place __init__.py file listed
below into some new subfolder in lib/python/Products folder and place
<dtml-nationaxmlizer>
nationalized text here with ěščřžýáíéďťňóúůöëäü
</dtml-nationaxmlizer>
text between these new tags in your page. Enjoy!
__init__.py:
from string import split, strip, join, find
import locale
import DocumentTemplate.DT_Util
from DocumentTemplate.DT_String import String
class NationaXMLizer:
"""
Function:
* Remove redundant whitespaces
based on 'unitws' tag from Toby Dickenson
<tdickenson at geminidataloggers.com>
* Replace characters >128 with &#xx; entities in respect with defined
codepage (cp1250), see znak.decode('yourcodepage') and define your own
Simply place this file named as __init__.py into some new subfolder in
lib/python/Products folder and place
<dtml-nationaxmlizer>
nationalized text here with national characters
</dtml-nationaxmlizer>
text between these new tags.
2005-01-24 by Jaroslav Lukesh, lukesh at seznam.cz
"""
name='nationaxmlizer'
blockContinuations=()
def __init__(self, blocks):
tname, args, section = blocks[0]
args = DocumentTemplate.DT_Util.parse_params(args)
self.blocks = section.blocks
def render(self,md):
data = DocumentTemplate.DT_Util.render_blocks(self.blocks, md)
a = []
for line in split(data,'\n'):
line = strip(line)
if line:
b = []
for word in split(line,' '):
if word!='':
wordxml=''
strip(word)
for i in range(len(word)):
znak=word[i]
n=ord(znak)
if n>= 128:
#this does not work in Pythoon 2.1.3!!!
#wordxml=wordxml+'&#'+(hex(ord(znak.decode('cp1250'))))+';'
wordxml=wordxml+'&#'+(hex(ord(unicode(znak,'cp1250'))))+';'
else:
wordxml=wordxml+znak
b.append(wordxml)
a.append(join(b,' '))
return join(a,'\n')
__call__=render
String.commands['nationaxmlizer']=NationaXMLizer
--
Jaroslav Lukesh
-----------------------------------------------------------
This e-mail can not contain any viruses because I use Linux
More information about the Zope
mailing list