功能:词条去重

Open
#551 6 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript, python

Research direction

The issue proposes a Python script to remove duplicate entries from static sections in locals.js. Start by checking how the localization files are structured and whether duplicate keys are present. The example script is only a proposal; done means the intended duplicate entries are removed without losing comments or other content.

Written by the indexing model from the issue text.

Description

enhancement

目前打算使用 python 脚本自动检测并去除重复词条
这是示例脚本:

import re

def remove_duplicates(file_path):
    # 读取文件内容
    with open(file_path, 'r', encoding='utf-8') as file:
        content = file.read()

    # 匹配所有 "static" 部分
    static_matches = re.finditer(r'"static": \{([\s\S]*?)\}', content)
    if not static_matches:
        print('未找到 "static" 部分。')
        return

    new_content = content  # 用于存储整体替换后的内容
    for match in static_matches:
        static_content = match.group(1)
        lines = static_content.split('\n')

        seen = set()  # 用于存储已出现的键名
        unique_lines = []  # 存储去重后的行

        # 遍历每一行,检查重复
        for line in lines:
            stripped_line = line.strip()
            if stripped_line and not stripped_line.startswith('//'):  # 排除注释和空行
                key_match = re.match(r'"(.*?)":', stripped_line)  # 提取键名
                if key_match:
                    key = key_match.group(1)
                    if key in seen:
                        print(f'重复项:{key}')
                        continue
                    seen.add(key)
            unique_lines.append(line)  # 保留非重复项、注释和空行

        # 将去重后的内容重新组装
        unique_content = '\n'.join(unique_lines)
        new_content = new_content.replace(static_content, unique_content)

    # 写入去重后的文件
    with open(file_path, 'w', encoding='utf-8') as file:
        file.write(new_content)
    print('所有重复项已移除并保存至文件。')


if __name__ == "__main__":
    # 文件路径
    file_path = './locals.js'  # 替换为你的文件路径
    remove_duplicates(file_path)
Dominant language
JavaScript
Stars
35.1k
Forks
2k
Avg merge
2d 1h
Merged PRs (30d)
9

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from maboloshi/github-chinese

All issues in maboloshi/github-chinese

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.