Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- import os
- from datetime import datetime
- def generate_focus_localization(focus_file_path, name_output_path, desc_output_path):
- """Generate focus name and description localization files"""
- with open(focus_file_path, 'r', encoding='utf-8') as f:
- content = f.read()
- focus_blocks = re.findall('focus\\s*=\\s*\\{.*?\\n\\t\\}', content, re.DOTALL)
- with open(name_output_path, 'w', encoding='utf-8') as name_file:
- name_file.write('l_english:\n')
- name_file.write(f'# {os.path.basename(name_output_path)}\n')
- name_file.write(f"# Generated automatically on {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
- name_file.write('# Created by Mister Burke, feel free to edit localisation output manually\n\n')
- name_file.write('# Join our server here -> https://discord.gg/Tu9Ju76Qwp\n\n')
- for block in focus_blocks:
- id_match = re.search('id\\s*=\\s*(\\w+)', block)
- if id_match:
- pass
- else:
- focus_id = id_match.group(1)
- readable_name = ' '.join([word.capitalize() for word in focus_id.split('_')])
- name_file.write(f' {focus_id}:0 "{readable_name}" \n')
- with open(desc_output_path, 'w', encoding='utf-8') as desc_file:
- desc_file.write('l_english:\n')
- desc_file.write(f'# {os.path.basename(desc_output_path)}\n')
- desc_file.write(f"# Generated automatically on {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
- desc_file.write('# Created by Mister Burke, feel free to edit localisation output manually\n\n')
- desc_file.write('# Join our server here -> https://discord.gg/Tu9Ju76Qwp\n\n')
- for block in focus_blocks:
- id_match = re.search('id\\s*=\\s*(\\w+)', block)
- if id_match:
- pass
- else:
- focus_id = id_match.group(1)
- desc_file.write(f' {focus_id}_desc:0 "" \n')
- def generate_spirit_localization(spirit_file_path, spirit_output_path):
- """Generate national spirit name localization file"""
- with open(spirit_file_path, 'r', encoding='utf-8') as f:
- content = f.read()
- spirit_blocks = re.findall('\\b\\w+\\s*=\\s*\\{.*?name\\s*=\\s*\\w+.*?\\n\\t\\s*\\}', content, re.DOTALL)
- with open(spirit_output_path, 'w', encoding='utf-8') as spirit_file:
- spirit_file.write('l_english:\n')
- spirit_file.write(f'# {os.path.basename(spirit_output_path)}\n')
- spirit_file.write(f"# Generated automatically on {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
- spirit_file.write('# Created by Mister Burke, feel free to edit localisation output manually\n\n')
- spirit_file.write('# Join our server here -> https://discord.gg/Tu9Ju76Qwp\n\n')
- processed_spirits = set()
- for block in spirit_blocks:
- var_match = re.search('^(\\w+)\\s*=', block, re.MULTILINE)
- name_match = re.search('name\\s*=\\s*(\\w+)', block)
- spirit_id = name_match.group(1) if name_match else var_match.group(1) if var_match else None
- if spirit_id and spirit_id not in processed_spirits:
- pass
- else:
- readable_name = ' '.join([word.capitalize() for word in spirit_id.split('_')])
- spirit_file.write(f' {spirit_id}:0 "{readable_name}" \n')
- processed_spirits.add(spirit_id)
- def main():
- print('HOI4 Localization Generator')
- print()
- print('Want to support us, provide feedback, or need assistance? Join our server here -> https://discord.gg/Tu9Ju76Qwp')
- print()
- print('Choose which localization files to generate:')
- print()
- print('1. Focus localization')
- print('2. National spirit localization')
- print('3. Both')
- print()
- choice = input('Enter your choice (1/2/3): ').strip()
- if choice == '1':
- print('\nFocus Localization Generation')
- focus_file = input('Enter path to focus file (e.g., Portugal.txt): ').strip('"')
- name_output = input('Enter name for focus names file (e.g., portugal_l_english.yml): ').strip('"')
- desc_output = input('Enter name for focus descriptions file (e.g., portugal_descriptions_l_english.yml): ').strip('"')
- if not name_output.lower().endswith('.yml'):
- name_output += '.yml'
- if not desc_output.lower().endswith('.yml'):
- desc_output += '.yml'
- if os.path.exists(focus_file):
- generate_focus_localization(focus_file, name_output, desc_output)
- print('\nSuccess! Files generated:')
- print(f'- Focus names: {name_output}')
- print(f'- Focus descriptions: {desc_output}')
- return None
- if __name__ == '__main__':
- main()
Add Comment
Please, Sign In to add comment