arcoI18nGenerate

arcoI18nGenerate

生成arcoPro的i18n文件

根据注释完善的JavaJPA实体类生成arcoPro的i18n文件

import re

def extract_fields(java_code):
    fields = re.findall(r'private\s+\w+\s+(\w+)\s*;', java_code)
    print(fields)
    javadocs = re.findall(r'\/\*\*\s*(.*?)\s*\*\/\s+private', java_code, re.DOTALL)
    print(javadocs)
    return fields, javadocs

def convert_to_camel_case(snake_case):
    return snake_case[0].lower() + snake_case[1:]

def parse_java_file(file_path):
    with open(file_path, 'r') as file:
        java_code = file.read().split('@Table')[1]
        class_name = re.search(r'class\s+(\w+)', java_code).group(1)
        pattern = r'/\*\*\s*(.*?)\*/.*?private\s+(\w+)\s+(\w+);'
        matches = re.findall(pattern, java_code, re.DOTALL)
        for match in matches:
            javadoc_comment = match[0].strip().replace('\n', ' ').replace('* ', '')
            field_type = match[1]
            field_name = match[2]
            print(f"'{convert_to_camel_case(class_name)}.{convert_to_camel_case(field_name)}': '{javadoc_comment}',")

# 用法示例
path = 'path/to/User.java'
parse_java_file(path)