Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修正了原本语言设定为zh-TW后仍然有简体字出现的问题 #247

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

CX330Blake
Copy link

@CX330Blake CX330Blake commented Jul 6, 2024

如题,原本的繁体设定并不会让所有字体都变为繁体,在此版本修復。修改方式为写了个Python的脚本递归的把资料夹内的所有简体字改为繁体,脚本如下。

import os
import opencc


def convert_simplified_to_traditional(file_path):
    # 初始化 opencc 转换器
    converter = opencc.OpenCC("s2t.json")

    try:
        # 尝试使用UTF-8编码读取文件内容
        with open(file_path, "r", encoding="utf-8") as file:
            content = file.read()
    except UnicodeDecodeError:
        print(f"Skipped (encoding issue): {file_path}")
        return

    # 转换简体字到繁体字
    converted_content = converter.convert(content)

    # 将转换后的内容写回文件
    with open(file_path, "w", encoding="utf-8") as file:
        file.write(converted_content)


def convert_files_in_directory(directory_path, skip_files):
    # 浏览资料夹内所有档案
    for root, dirs, files in os.walk(directory_path):
        for file in files:
            if file in skip_files:
                print(f"Skipped (by name): {os.path.join(root, file)}")
                continue
            file_path = os.path.join(root, file)
            # 处理文件
            convert_simplified_to_traditional(file_path)
            print(f"Converted: {file_path}")


# 设定资料夹路径
directory_path = "D:/GitHub/hexo-theme-anzhiyu-TW"
# 设定需要跳过的档名,为了翻译功能不会失效
skip_files = ["tw_cn.js"]

# 转换资料夹内所有档案的简体字为繁体字,跳过特定档案
convert_files_in_directory(directory_path, skip_files)

@CX330Blake
Copy link
Author

示范页面:https://cx330.tw

@anzhiyu-c
Copy link
Owner

这样会导致简体完全失效,所以暂时不会被pr。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants