先修复一下,错误的场景 删除不必要的钓场资产 修复into场景 update:更新meta文件,修复报错 update:修复资源 修复第一章节建造 修复建造第三章 update:删除多余内容 update:更新README.md update:还原图标 update:更新README update:更新配置
46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""
|
||
将 boostrapi18n.csv 转换为 boostrapi18n.tsv
|
||
- 单元格内真实换行写成字面 \\r\\n,制表符写成字面 \\t,避免破坏列
|
||
- 不用引号包裹字段,输出无首尾 "
|
||
"""
|
||
import csv
|
||
import os
|
||
|
||
def _normalize_cell(cell):
|
||
"""还原 CSV 双引号转义;真实换行/制表符改为字面 \\r\\n、\\t,避免输出时被加引号"""
|
||
if not isinstance(cell, str):
|
||
return cell
|
||
s = cell.replace('""', '"')
|
||
s = s.replace('\r\n', '\\r\\n').replace('\n', '\\r\\n').replace('\r', '\\r\\n')
|
||
s = s.replace('\t', '\\t') # 单元格内真实 tab 写成 \t,避免破坏列
|
||
return s
|
||
|
||
def convert_csv_to_tsv():
|
||
csv_file = 'boostrapi18n.csv'
|
||
tsv_file = 'boostrapi18n.tsv'
|
||
|
||
if not os.path.exists(csv_file):
|
||
print(f'错误: 找不到文件 {csv_file}')
|
||
return False
|
||
|
||
try:
|
||
with open(csv_file, 'r', encoding='utf-8') as f_in:
|
||
reader = csv.reader(f_in)
|
||
rows = [[_normalize_cell(cell) for cell in row] for row in reader]
|
||
|
||
# 手动按 \t 拼接行,不经过会加引号的 writer,保证无首尾 "
|
||
with open(tsv_file, 'w', encoding='utf-8', newline='') as f_out:
|
||
for row in rows:
|
||
f_out.write('\t'.join(row) + '\n')
|
||
|
||
print(f'成功: {csv_file} 已转换为 {tsv_file}')
|
||
return True
|
||
|
||
except Exception as e:
|
||
print(f'错误: 转换失败 - {str(e)}')
|
||
return False
|
||
|
||
if __name__ == '__main__':
|
||
convert_csv_to_tsv()
|