运行效果:
如果你的某个目录只有一种语言:如简体中文(gb2312)schinese,那么它会自动转换并生成另一个utf编码的目录schineseutf
如果你的某个目录只有utf编码的目录schineseutf,那么它会自动转换并生成另一个简体中文编码(gb2312)的目录schinese.
如果某个目录中这两个目录都存在,它会显示all,并处理下一个。
如果某个目录中没有这两个目录,它会显示None,并处理下一个(如:class/xoopseditor/koivi/language目录不会补处理)。
运行条件:linux+python2.4及以上,2.3中没有cp936编码。
运行方法:请将以下代码下载并保存在xoops_root目录下autoconver.py,然后更改属性为可执行:chmod u+x autoconver.py
运行:./autoconver.py
本人只进行过一部分测试,没有进行全面测试,所以请大家在使用过程中遇到什么问题及时提出,本人再做改进。
提醒一点:用此工具完成转换之后,请手动修改一下xoops_root/language/xxxxxx/global.php文件中的编码设置,程序在此没有处理。改天有时间再完善。
附源代码:
如果你有兴趣,请完善并重新发布它,呵呵。
如果你的某个目录只有一种语言:如简体中文(gb2312)schinese,那么它会自动转换并生成另一个utf编码的目录schineseutf
如果你的某个目录只有utf编码的目录schineseutf,那么它会自动转换并生成另一个简体中文编码(gb2312)的目录schinese.
如果某个目录中这两个目录都存在,它会显示all,并处理下一个。
如果某个目录中没有这两个目录,它会显示None,并处理下一个(如:class/xoopseditor/koivi/language目录不会补处理)。
运行条件:linux+python2.4及以上,2.3中没有cp936编码。
运行方法:请将以下代码下载并保存在xoops_root目录下autoconver.py,然后更改属性为可执行:chmod u+x autoconver.py
运行:./autoconver.py
本人只进行过一部分测试,没有进行全面测试,所以请大家在使用过程中遇到什么问题及时提出,本人再做改进。
提醒一点:用此工具完成转换之后,请手动修改一下xoops_root/language/xxxxxx/global.php文件中的编码设置,程序在此没有处理。改天有时间再完善。
附源代码:
如果你有兴趣,请完善并重新发布它,呵呵。
#!/usr/bin/env python2.4
# -*- encoding: utf8 -*-
# Filename: autoconver.py
# Discripion:
# Author(s): yetist
# Version: 0.2
import sys
import os
import time
def find_lang_dir():
for root, dirs, files in os.walk( os.getcwd()):
for dir in dirs:
path = os.path.join( root, dir )
curdirname=root.split("/")[-1:][0]
if curdirname=="language" :
process_lang(root)
time.sleep(1)
def process_lang(dir=None):
print "process dir: %s" % dir
schinese=False
schineseutf=False
for i in os.listdir(dir):
if i =="schinese":
schinese=True
if i =="schineseutf":
schineseutf=True
if schinese == True and schineseutf == True:
print "all"
return
if schinese == False and schineseutf == True:
print "translate schineseutf to schinese"
convert_dir_to_dir(os.path.join(dir,"schineseutf"),os.path.join(dir,"schinese"),"zh_utf","zh_cn")
return
if schinese == True and schineseutf == False:
print "translate schinese to eschineseutf"
convert_dir_to_dir(os.path.join(dir,"schinese"),os.path.join(dir,"schineseutf"),"zh_cn","zh_utf")
return
if os.path.isdir(os.path.join(dir,i)):
print ">>>find other language in this dir: %s" % i
print "None"
def convert_dir_to_dir(srcdir,dstdir,fcode,tocode):
time.sleep(1)
if not os.path.exists(dstdir):
os.mkdir(dstdir)
for root, dirs, files in os.walk(srcdir):
for dir in dirs:
ndir=os.path.join(root,dir)
dirpath=ndir.replace(srcdir,"")[1:]
ndstdir = os.path.join(dstdir,dirpath)
if not os.path.exists(ndstdir):
os.mkdir(ndstdir)
for root, dirs, files in os.walk(srcdir):
for file in files:
srcfile = os.path.join( root, file )
dpath=srcfile.replace(srcdir,"")[1:]
dstfile = os.path.join(dstdir,dpath)
print ">>>>>>>nconvert start [from %s ]:%s" % (fcode,srcfile)
print "<<<<<<<nconvert end. [to %s ]:%s" % (tocode,dstfile)
time.sleep(1)
file_trans(srcfile,dstfile,fcode,tocode)
def file_trans(srcfile,dstfile,fcode="zh_cn",tocode="zh_utf"):
transcode={"zh_cn":"cp936","zh_tw":"big5","zh_utf":"utf-8"}
fp=open(srcfile,"r")
str=fp.read()
fp.close()
obj=unicode(str,transcode.get(fcode)).encode(transcode.get(tocode))
fp=open(dstfile,"w+")
fp.write(obj)
fp.close()
if __name__ == "__main__":
find_lang_dir()