马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 SlanKi 于 2026-8-7 21:54 编辑
起因是这样的,在制作游戏本地化时发现作者写了
[RenPy] 纯文本查看 复制代码 def alter_say_strings( str_to_test ):
str_map = {
". " : ". {w=0.27}",
".' " : ".' {w=0.2}",
", " : ", {w=0.15}",
",' " : ",' {w=0.15}",
"! " : "! {w=0.27}",
"? " : "? {w=0.27}",
"— " : "— {w=0.27}",
": " : ": {w=0.27}",
"; " : "; {w=0.27}",
" (" : "{w=0.2} (",
") " : "){w=0.2} ",
}
for key in str_map:
str_to_test = str_to_test.replace( key, str_map[ key ] )
return str_to_test
config.say_menu_text_filter = alter_say_strings
以这样的方式来实现句子的自动停顿,但因为config.say_menu_text_filter在官方文档中写的会传入menu,且运行在翻译层之前,string被修改跟翻译匹配不上导致选项丢翻译。
折腾了好几个小时无果后,在尝试修改时在alter_say_strings( str_to_test )函数头部加上print(str(str_to_test))发现传入的say是翻译后的文本,而menu是未翻译的文本。百思不得其解,按官方文档写的
“A list of functions that are given the text found in strings in the say and menu statements. Each is expected to return new (or the same) strings to replace them.
These run very early in the say and menu statement processing, before translation and substitutions are applied. For a filter that runs later, see config.replace_text.”
无论say还是menu应该都是传入翻译前的文本,但莫名其妙偏偏say是没绕过翻译的,menu是绕过翻译的。导致现在写了一串很抽象的代码塞在alter_say_strings( str_to_test )来解决,求大佬支招,以及这个say没绕过翻译层又是什么情况。
Ren'Py 8.3.7.25031702和Ren'Py 7.5.0.22062402都有这个问题,也试过改用config.replace_text但会直接把插入的{w=0.xx}当文字显示出来。以下是我目前在alter_say_strings( str_to_test )函数里插入的代码:
[RenPy] 纯文本查看 复制代码 force_trans = renpy.translate_string(
str_to_test,
renpy.game.preferences.language
)
if force_trans != str_to_test:
return force_trans
|