Project Zomboid

Project Zomboid

Hephas Comics
Fragger 21 Aug, 2024 @ 4:53pm
Localization suggestion
Buddy, I think you shouldn't write the contents of scripts in this format, you should make them line by line. I can't even extract the "Item_EN.txt" file with python, it's a huge challenge for localization

This python script helps you to arrange everything inside "HephasComics_items.txt" in an intuitive format. Running it inside the scripts folder and typing in the filename will generate a new file
import re def format_text(text): # 匹配item块 items = re.findall(r'(item\s+\w+\s*\{[^}]+\})', text, re.DOTALL) formatted_items = [] for item in items: # 匹配item名和内容 match = re.match(r'(item\s+\w+)\s*\{([^}]+)\}', item, re.DOTALL) if match: item_name = match.group(1) properties = match.group(2).strip().split(',') # 处理属性,确保等号前后只有一个空格 formatted_properties = ',\n '.join(re.sub(r'\s*=\s*', ' = ', prop.strip()) for prop in properties if prop.strip()) formatted_item = f' {item_name}\n {{\n {formatted_properties},\n }}' formatted_items.append(formatted_item) # 将所有格式化后的item块组合 formatted_text = 'module Base\n{\n' + '\n\n'.join(formatted_items) + '\n}' return formatted_text def main(): # 获取文件名 filename = input("Enter the name of the file to be formatted (with extension):") try: # 读取文件内容 with open(filename, 'r', encoding='utf-8') as file: text = file.read() # 格式化文本 formatted_text = format_text(text) # 生成输出文件名 output_filename = f"formatted_{filename}" # 将格式化后的文本写入新文件 with open(output_filename, 'w', encoding='utf-8') as file: file.write(formatted_text) print(f"文件已成功格式化并保存为 {output_filename}") except FileNotFoundError: print("文件未找到,请检查文件名并重试。") except Exception as e: print(f"发生错误:{e}") if __name__ == "__main__": main()
Last edited by Fragger; 21 Aug, 2024 @ 4:58pm
< >
Showing 1-4 of 4 comments
Fragger 21 Aug, 2024 @ 4:54pm 
Then you can extract the "ItemName_EN.txt" file using this python script, just put it in the same directory.

import os import re def extract_display_names(filepath): with open(filepath, 'r', encoding='utf-8') as file: content = file.read() # 匹配 module 名称 module_match = re.search(r'module\s+(\w+)', content) if not module_match: return [] module_name = module_match.group(1) item_entries = [] # 匹配 item 块 items = re.findall(r'item\s+(\w+)\s*\{[^}]*?DisplayName\s*=\s*([^,]+)', content, re.DOTALL) for item_name, display_name in items: item_entry = f'ItemName_{module_name}.{item_name} = "{display_name.strip()}",' item_entries.append(item_entry) return item_entries def main(): # 获取当前脚本所在的目录 directory = os.path.dirname(os.path.abspath(__file__)) # 初始化保存所有提取内容的列表 all_entries = [] # 遍历目录中的所有txt文件 for filename in os.listdir(directory): if filename.endswith(".txt"): filepath = os.path.join(directory, filename) entries = extract_display_names(filepath) all_entries.extend(entries) # 如果有提取的内容,写入到 ItemName_EN.txt 文件 if all_entries: output_filepath = os.path.join(directory, "ItemName_EN.txt") with open(output_filepath, 'w', encoding='utf-8') as output_file: output_file.write("ItemName_EN = {\n") output_file.write("\n".join(f" {entry}" for entry in all_entries)) output_file.write("\n}\n") print(f"提取的内容已保存到 {output_filepath}") else: print("未找到任何符合条件的内容。") if __name__ == "__main__": main()
Last edited by Fragger; 21 Aug, 2024 @ 4:55pm
Fragger 21 Aug, 2024 @ 4:56pm 
This is the "ItemName_EN.txt" I extracted
ItemName_EN = { ItemName_Base.Hephas_Comic = "Hephas Comic Item", ItemName_Base.SpecialSealedComicBook = "Special Comic Package", ItemName_Base.SealedComicBook = "Comic Package", ItemName_Base.HC_TASM1 = "The Amazing Spiderman #1", ItemName_Base.HC_TASM2 = "The Amazing Spiderman #2", ItemName_Base.HC_TASM3 = "The Amazing Spiderman #3", ItemName_Base.HC_TASM4 = "The Amazing Spiderman #4", ItemName_Base.HC_TASM5 = "The Amazing Spiderman #5", ItemName_Base.HC_TAOV1 = "The Avengers Omnibus Vol.1", ItemName_Base.HC_TAOV2 = "The Avengers Omnibus Vol.2", ItemName_Base.HC_TAOV3 = "The Avengers Omnibus Vol.3", ItemName_Base.HC_TAOV4 = "The Avengers Omnibus Vol.4", ItemName_Base.HC_TAOV5 = "The Avengers Omnibus Vol.5", ItemName_Base.HC_TD1 = "The Defenders #1", ItemName_Base.HC_TD2 = "The Defenders #2", ItemName_Base.HC_TD3 = "The Defenders #3", ItemName_Base.HC_TD4 = "The Defenders #4", ItemName_Base.HC_TD5 = "The Defenders #5", ItemName_Base.HC_TTOD1 = "The Tomb Of Dracula #1", ItemName_Base.HC_TTOD2 = "The Tomb Of Dracula #2", ItemName_Base.HC_TTOD3 = "The Tomb Of Dracula #3", ItemName_Base.HC_TTOD4 = "The Tomb Of Dracula #4", ItemName_Base.HC_TTOD5 = "The Tomb Of Dracula #5", ItemName_Base.HC_BLOTDK1 = "Batman: Legends of the Dark Knight #1", ItemName_Base.HC_BLOTDK2 = "Batman: Legends of the Dark Knight #2", ItemName_Base.HC_BLOTDK3 = "Batman: Legends of the Dark Knight #3", ItemName_Base.HC_BLOTDK4 = "Batman: Legends of the Dark Knight #4", ItemName_Base.HC_BLOTDK5 = "Batman: Legends of the Dark Knight #5", ItemName_Base.HC_MKCE1 = "Mortal Combat Collector's Edition I", ItemName_Base.HC_MKCE2 = "Mortal Combat Collector's Edition II", ItemName_Base.HC_TDP1 = "The Doom Partrol #86", ItemName_Base.HC_TDP2 = "The Doom Partrol #87", ItemName_Base.HC_NTG1 = "The New Gods #1", ItemName_Base.HC_SW1 = "Star Wars #41", ItemName_Base.HC_SW2 = "Star Wars #42", ItemName_Base.HC_SW3 = "Star Wars #43", ItemName_Base.HC_SW4 = "Star Wars #68", ItemName_Base.HC_SW5 = "Star Wars #81", ItemName_Base.HC_TUXM1 = "The Uncanny X-Men #130", ItemName_Base.HC_TUXM2 = "The Uncanny X-Men #132", ItemName_Base.HC_TUXM3 = "The Uncanny X-Men #133", ItemName_Base.HC_TUXM4 = "The Uncanny X-Men #134", ItemName_Base.HC_ALB2 = "Albedo Anthropomorphics #2", ItemName_Base.HC_CLI1 = "Cliffhanger 12", ItemName_Base.HC_JCH1 = "John Contantine Hellblazer No.1", ItemName_Base.HC_JCH2 = "John Contantine Hellblazer No.2", ItemName_Base.HC_MAY1 = "Mayhem #1", ItemName_Base.HC_SPI1 = "Spirit No.1", ItemName_Base.HC_TUR1 = "Turtlemania Special #1", ItemName_Base.HC_UY1 = "Usagi Yojimbo #1", ItemName_Base.HC_PRE1 = "Predator #1", ItemName_Base.HC_WAT1 = "Watchmen #1", ItemName_Base.HC_BTKJ1 = "Batman The Killing Joke", ItemName_Base.HC_SPIFFO1 = "Spiffo's Adventures - Long Journey Into The Woods", ItemName_Base.HC_SPIFFO2 = "Spiffo's Adventures - Lost in the Woods", ItemName_Base.HC_SPIFFO3 = "Spiffo's Adventures - Searching For Jobs", ItemName_Base.HC_SPIFFO4 = "Spiffo's Adventures - Suspicious New Job", ItemName_Base.HC_SPIFFO5 = "Spiffo's Adventures - Dangerous Mission", ItemName_Base.HC_SPIFFO6 = "Spiffo's Adventures - Dangerous Mission Vol 2", ItemName_Base.HC_SPIFFO7 = "Spiffo's Adventures - Sahara Troubles", ItemName_Base.HC_SPIFFO8 = "Spiffo's Adventures - Pharaoh's Curse", ItemName_Base.HC_THOR1 = "The Might Thor #399", ItemName_Base.HC_THOR2 = "The Might Thor #411", ItemName_Base.HC_THOR3 = "The Might Thor #416", ItemName_Base.HC_TER1 = "Terminator 2 Judgment Day Vol.1", ItemName_Base.HC_TER2 = "Terminator 2 Judgment Day Vol.2", ItemName_Base.HC_TER3 = "Terminator 2 Judgment Day Vol.3", ItemName_Base.HC_IRON1 = "Iron Man #190", ItemName_Base.HC_IRON2 = "Iron Man #191", ItemName_Base.HC_IRON3 = "Iron Man #192", ItemName_Base.HC_CTK1 = "Conan The King #53", ItemName_Base.HC_CTK2 = "Conan The King #54", ItemName_Base.HC_CTK3 = "Conan The King #55", ItemName_Base.HC_CAP1 = "Captain America #364", ItemName_Base.HC_CAP2 = "Captain America #365", ItemName_Base.HC_CAP3 = "Captain America #370", ItemName_Base.HC_TSWOC1 = "The Savage Sword Of Conan The Barbarian", ItemName_Base.HC_WOLV1 = "Wolverine #312", ItemName_Base.HC_DD1 = "Daredevil #209", ItemName_Base.HC_BGBG1 = "A Tale Of The Batman: Gotham By Gaslight", ItemName_Base.HC_Berserk1 = "Berserk The Prototype", ItemName_Base.HC_SIN1 = "Sin City Vol.1", ItemName_Base.HC_SIN2 = "Sin City Vol.2", ItemName_Base.HC_SIN3 = "Sin City Vol.3", ItemName_Base.HC_TMNT1 = "TMNT: Comic Strips Introduction", ItemName_Base.HC_TMNT2 = "TMNT: Raphael #1", ItemName_Base.HC_2000AD1 = "2000AD: PROG 500", ItemName_Base.HC_TASM1_Read = "The Amazing Spiderman #1", ItemName_Base.HC_TASM1_Read = "The Amazing Spiderman #1 (Used)", ItemName_Base.HC_TASM2_Read = "The Amazing Spiderman #2 (Used)", ItemName_Base.HC_TASM3_Read = "The Amazing Spiderman #3 (Used)", ItemName_Base.HC_TASM4_Read = "The Amazing Spiderman #4 (Used)", ItemName_Base.HC_TASM5_Read = "The Amazing Spiderman #5 (Used)", ItemName_Base.HC_TAOV1_Read = "The Avengers Omnibus Vol.1 (Used)", ItemName_Base.HC_TAOV2_Read = "The Avengers Omnibus Vol.2 (Used)", ItemName_Base.HC_TAOV3_Read = "The Avengers Omnibus Vol.3 (Used)", ItemName_Base.HC_TAOV4_Read = "The Avengers Omnibus Vol.4 (Used)", ItemName_Base.HC_TAOV5_Read = "The Avengers Omnibus Vol.5 (Used)", ItemName_Base.HC_TD1_Read = "The Defenders #1 (Used)", ItemName_Base.HC_TD2_Read = "The Defenders #2 (Used)", ItemName_Base.HC_TD3_Read = "The Defenders #3 (Used)", ItemName_Base.HC_TD4_Read = "The Defenders #4 (Used)", ItemName_Base.HC_TD5_Read = "The Defenders #5 (Used)", ItemName_Base.HC_TTOD1_Read = "The Tomb Of Dracula #1 (Used)", ItemName_Base.HC_TTOD2_Read = "The Tomb Of Dracula #2 (Used)", ItemName_Base.HC_TTOD3_Read = "The Tomb Of Dracula #3 (Used)", ItemName_Base.HC_TTOD4_Read = "The Tomb Of Dracula #4 (Used)", ItemName_Base.HC_TTOD5_Read = "The Tomb Of Dracula #5 (Used)", ItemName_Base.HC_BLOTDK1_Read = "Batman: Legends of the Dark Knight #1 (Used)", ItemName_Base.HC_BLOTDK2_Read = "Batman: Legends of the Dark Knight #2 (Used)", ItemName_Base.HC_BLOTDK3_Read = "Batman: Legends of the Dark Knight #3 (Used)", ItemName_Base.HC_BLOTDK4_Read = "Batman: Legends of the Dark Knight #4 (Used)", ItemName_Base.HC_BLOTDK5_Read = "Batman: Legends of the Dark Knight #5 (Used)", ItemName_Base.HC_MKCE1_Read = "Mortal Combat Collector's Edition I (Used)", ItemName_Base.HC_MKCE2_Read = "Mortal Combat Collector's Edition II (Used)", ItemName_Base.HC_TDP1_Read = "The Doom Partrol #86 (Used)", ItemName_Base.HC_TDP2_Read = "The Doom Partrol #87 (Used)", ItemName_Base.HC_NTG1_Read = "The New Gods #1 (Used)", ItemName_Base.HC_SW1_Read = "Star Wars #41 (Used)", ItemName_Base.HC_SW2_Read = "Star Wars #42 (Used)", ItemName_Base.HC_SW3_Read = "Star Wars #43 (Used)", ItemName_Base.HC_SW4_Read = "Star Wars #68 (Used)", ItemName_Base.HC_SW5_Read = "Star Wars #81 (Used)", ItemName_Base.HC_TUXM1_Read = "The Uncanny X-Men #130 (Used)", ItemName_Base.HC_TUXM2_Read = "The Uncanny X-Men #132 (Used)", ItemName_Base.HC_TUXM3_Read = "The Uncanny X-Men #133 (Used)", ItemName_Base.HC_TUXM4_Read = "The Uncanny X-Men #134 (Used)", ItemName_Base.HC_ALB2_Read = "Albedo Anthropomorphics #2 (Used)", ItemName_Base.HC_CLI1_Read = "Cliffhanger 12 (Used)", ItemName_Base.HC_JCH1_Read = "John Contantine Hellblazer No.1 (Used)", ItemName_Base.HC_JCH2_Read = "John Contantine Hellblazer No.2 (Used)", ItemName_Base.HC_MAY1_Read = "Mayhem #1 (Used)", ItemName_Base.HC_SPI1_Read = "Spirit No.1 (Used)", ItemName_Base.HC_TUR1_Read = "Turtlemania Special #1 (Used)", ItemName_Base.HC_UY1_Read = "Usagi Yojimbo #1 (Used)", ItemName_Base.HC_PRE1_Read = "Predator #1 (Used)", ItemName_Base.HC_WAT1_Read = "Watchmen #1 (Used)", ItemName_Base.HC_BTKJ1_Read = "Batman The Killing Joke (Used)", ItemName_Base.HC_SPIFFO1_Read = "Spiffo's Adventures - Long Journey Into The Woods (Used)", ItemName_Base.HC_SPIFFO2_Read = "Spiffo's Adventures - Lost in the Woods (Used)", ItemName_Base.HC_SPIFFO3_Read = "Spiffo's Adventures - Searching For Jobs (Used)", ItemName_Base.HC_SPIFFO4_Read = "Spiffo's Adventures - Suspicious New Job (Used)", ItemName_Base.HC_SPIFFO5_Read = "Spiffo's Adventures - Dangerous Mission (Used)", ItemName_Base.HC_SPIFFO6_Read = "Spiffo's Adventures - Dangerous Mission Vol 2 (Used)", ItemName_Base.HC_SPIFFO7_Read = "Spiffo's Adventures - Sahara Troubles (Used)", ItemName_Base.HC_SPIFFO8_Read = "Spiffo's Adventures - Pharaoh's Curse (Used)", ItemName_Base.HC_THOR1_Read = "The Might Thor #399 (Used)", ItemName_Base.HC_THOR2_Read = "The Might Thor #411 (Used)", ItemName_Base.HC_THOR3_Read = "The Might Thor #416 (Used)", ItemName_Base.HC_TER1_Read = "Terminator 2 Judgment Day Vol.1 (Used)", ItemName_Base.HC_TER2_Read = "Terminator 2 Judgment Day Vol.2 (Used)", ItemName_Base.HC_TER3_Read = "Terminator 2 Judgment Day Vol.3 (Used)", ItemName_Base.HC_IRON1_Read = "Iron Man #190 (Used)", ItemName_Base.HC_IRON2_Read = "Iron Man #191 (Used)", ItemName_Base.HC_IRON3_Read = "Iron Man #192(Used)", ItemName_Base.HC_CTK1_Read = "Conan The King #53 (Used)", ItemName_Base.HC_CTK2_Read = "Conan The King #54 (Used)", ItemName_Base.HC_CTK3_Read = "Conan The King #55 (Used)", ItemName_Base.HC_CAP1_Read = "Captain America #364 (Used)", ItemName_Base.HC_CAP2_Read = "Captain America #365 (Used)", ItemName_Base.HC_CAP3_Read = "Captain America #370 (Used)", ItemName_Base.HC_TSWOC1_Read = "The Savage Sword Of Conan The Barbarian (Used)", ItemName_Base.HC_WOLV1_Read = "Wolverine #312 (Used)", ItemName_Base.HC_DD1_Read = "Daredevil #209 (Used)", ItemName_Base.HC_BGBG1_Read = "A Tale Of The Batman: Gotham By Gaslight (Used)", ItemName_Base.HC_Berserk1_Read = "Berserk The Prototype (Used)", ItemName_Base.HC_SIN1_Read = "Sin City Vol.1 (Used)", ItemName_Base.HC_SIN2_Read = "Sin City Vol.2 (Used)", ItemName_Base.HC_SIN3_Read = "Sin City Vol.3 (Used)", ItemName_Base.HC_TMNT1_Read = "TMNT: Comic Strips Introduction (Used)", ItemName_Base.HC_TMNT2_Read = "TMNT: Raphael #1 (Used)", ItemName_Base.HC_2000AD1_Read = "2000AD: PROG 500 (Used)", }
Hephaistos  [developer] 21 Aug, 2024 @ 11:21pm 
Originally posted by Fͥraͣgͫger:
Buddy, I think you shouldn't write the contents of scripts in this format, you should make them line by line. I can't even extract the "Item_EN.txt" file with python, it's a huge challenge for localization

This python script helps you to arrange everything inside "HephasComics_items.txt" in an intuitive format. Running it inside the scripts folder and typing in the filename will generate a new file
import re def format_text(text): # 匹配item块 items = re.findall(r'(item\s+\w+\s*\{[^}]+\})', text, re.DOTALL) formatted_items = [] for item in items: # 匹配item名和内容 match = re.match(r'(item\s+\w+)\s*\{([^}]+)\}', item, re.DOTALL) if match: item_name = match.group(1) properties = match.group(2).strip().split(',') # 处理属性,确保等号前后只有一个空格 formatted_properties = ',\n '.join(re.sub(r'\s*=\s*', ' = ', prop.strip()) for prop in properties if prop.strip()) formatted_item = f' {item_name}\n {{\n {formatted_properties},\n }}' formatted_items.append(formatted_item) # 将所有格式化后的item块组合 formatted_text = 'module Base\n{\n' + '\n\n'.join(formatted_items) + '\n}' return formatted_text def main(): # 获取文件名 filename = input("Enter the name of the file to be formatted (with extension):") try: # 读取文件内容 with open(filename, 'r', encoding='utf-8') as file: text = file.read() # 格式化文本 formatted_text = format_text(text) # 生成输出文件名 output_filename = f"formatted_{filename}" # 将格式化后的文本写入新文件 with open(output_filename, 'w', encoding='utf-8') as file: file.write(formatted_text) print(f"文件已成功格式化并保存为 {output_filename}") except FileNotFoundError: print("文件未找到,请检查文件名并重试。") except Exception as e: print(f"发生错误:{e}") if __name__ == "__main__": main()

Hey Fragger!

Thanks for the advice! But I think localizing the titles in that mod doesn’t really make sense since names like Iron Man, Star Wars, The Defenders, Tomb of Dracula, and Doom Patrol are the same in German, Russian, Ukrainian, and most other (at least European) languages. (I have no clue about Mandarin though.) The same goes for almost all comic titles, except for a few like Spiffo’s Adventure, A Tale of Batman, etc., which I’ll streamline in future updates.

I’ve structured the script content intentionally the way it is to avoid having 2k lines and to keep a better overview for myself. It’s more intuitive for the use case in this mod.

What would actually be helpful is translating the tooltips instead of item names. That kind of localization would make much more sense!

Thanks for the Python script btw! It will help with my next project. :spiffo:
Fragger 22 Aug, 2024 @ 4:39am 
Originally posted by Hephaistos:
Hey Fragger!

Thanks for the advice! But I think localizing the titles in that mod doesn’t really make sense since names like Iron Man, Star Wars, The Defenders, Tomb of Dracula, and Doom Patrol are the same in German, Russian, Ukrainian, and most other (at least European) languages. (I have no clue about Mandarin though.) The same goes for almost all comic titles, except for a few like Spiffo’s Adventure, A Tale of Batman, etc., which I’ll streamline in future updates.

I’ve structured the script content intentionally the way it is to avoid having 2k lines and to keep a better overview for myself. It’s more intuitive for the use case in this mod.

What would actually be helpful is translating the tooltips instead of item names. That kind of localization would make much more sense!

Thanks for the Python script btw! It will help with my next project. :spiffo:
NP. You're welcome.

Okay, if this helps you manage updates then it's best to leave it as is.

I was able to extract it from the file myself, but maybe you could include the ItemName in the original file? That would help others who want to translate them.

And, thank you for your excellent work!
< >
Showing 1-4 of 4 comments
Per page: 1530 50