找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 6408|回复: 1

[软件/工具] 汉化字体patch一键生成脚本

[复制链接]
发表于 2020-5-9 13:52:14 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
本帖最后由 Ag2S 于 2020-5-9 13:51 编辑

复制以下代码,保存为py文件,放到游戏的game目录的上层目录,运行(需要安装python)。
[RenPy] 纯文本查看 复制代码
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
import re


def getFontsList():
    fs=[]
    fs.append('DejaVuSans.ttf')
    dirpath='game'
    for root,dirs,files in os.walk(dirpath):
        for file in files:
            if((file.endswith('.ttf') or file.endswith('.otf')) and 'tl' not in root):
                fs.append(os.path.join(root,file).replace('\\','/').replace('game/',''))
    return fs
    
def getSourceFiles():
    fs=[]
    dirpath='game'
    for root,dirs,files in os.walk(dirpath):
        for file in files:
            if(file.endswith('.rpy') and 'tl' not in root):
                fs.append(os.path.join(root,file).replace('\\','/'))
    return fs
def getStylesName(files):
    styles=[]
    styles.append('default')
    for name in files:
        lines=open(name,mode='r',encoding='utf-8').readlines( )
        for line in lines:
            b1= re.search('style (.*):', line)
            if(b1):
                name=b1.group(1)
                b2=' ' not in name
                if(b2):
                    #print(name)
                    styles.append(name)
                    
    styles=list(set(styles))
    return styles
    
    
def genratePatch(fonts,styles,path):
    patch=open('patch.rpy',mode='w',encoding='utf-8')
    patch.write('##汉化Patch由Ag2S20150909制作\n')
    patch.write('##This chinese Patch made by Ag2S20150909\n')
    ##python初始化
    patch.write('init 200  python:\n')
    patch.write("   config.language='chinese'\n")
    patch.write("   if config.language=='chinese':\n")
    for f in fonts:
        patch.write("        config.font_replacement_map[\"%s\", True, True] = (\"%s\", True, True)\n" %(f,path))
        patch.write("        config.font_replacement_map[\"%s\", False, False] = (\"%s\", False, False)\n" %(f,path))
        patch.write("        config.font_replacement_map[\"%s\", True, False] = (\"%s\", True, False)\n" %(f,path))
        patch.write("        config.font_replacement_map[\"%s\", False,True] = (\"%s\", False,True)\n" %(f,path))
        
    for st in styles:
        patch.write('translate chinese style %s:\n    font "%s"\n' %(st,path))
        
    patch.write('\ntranslate chinese python:\n')
    patch.write('    gui.button_text_font = "%s"\n' %(path))
    patch.write('    gui.glyph_font = "%s"\n' %(path))
    patch.write('    gui.interface_text_font = "%s"\n' %(path))
    patch.write('    gui.text_font = "%s"\n' %(path))
    patch.write('    gui.name_text_font = "%s"\n' %(path))
    
    
##中文字体的相对路径    
path='tl/chinese/patch/Alibaba-PuHuiTi-Regular.ttf'
files=getSourceFiles()
styles=getStylesName(files)
fonts=getFontsList()
    
genratePatch(fonts,styles,path)



评分

参与人数 1干货 +1 收起 理由
BuErShen + 1 感谢分享!

查看全部评分

发表于 2020-6-5 13:43:43 | 显示全部楼层
看脚本是将对应字体全替换掉?
不过适用于直接原脚本里进行翻译的
回复 支持 抱歉

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|RenPy中文空间 ( 苏ICP备17067825号|苏公网安备 32092302000068号 )

GMT+8, 2024-4-26 12:24 , Processed in 0.055207 second(s), 14 queries , File On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表