- Jul 11, 2017
- 931
- 708
I just opened the addon options and saw that even addons that rely on third-party repos like GPT4All are restricted. wow! is there a hub of addons developed by the community?
import requests
import re
import json
# Path to the text file on your computer
raw_path = "cntd.txt"
text_path = "cntd(translated).txt"
# Function to read content from a text file on the computer
def read_file_content(file_path):
try:
with open(file_path, 'r', encoding='utf-8') as file:
content = file.readlines() # Read file by line
return content
except FileNotFoundError:
print(f"File {file_path} does not exist.")
return None
# Function to write content to a file
def write_file_content(file_path, content):
try:
with open(file_path, 'a', encoding='utf-8') as file:
file.write(content + "\n") # Add newline after each piece of content
print(f"Result has been written to file {file_path}")
except Exception as e:
print(f"An error occurred while writing to the file: {e}")
# Function to send an API request
def send_api_request(text_content):
url = "https://api.dichnhanh.com/"
# Form data you provided
# type: "Modern", "Ancient"
data = {
"type": "Ancient",
"enable_analyze": 1,
"enable_fanfic": 0,
"mode": "qt",
"text": text_content, # Text content from file
"remove": ""
}
# Send POST request to API
try:
response = requests.post(url, data=data)
if response.status_code == 200:
return response.text
else:
print(f"Error {response.status_code}: {response.text}")
return None
except Exception as e:
print("An error occurred:", e)
return None
# Capitalize the first letter immediately after a newline
def capitalize_after_newline(text):
lines = text.split('\n') # Split text by newline
capitalized_lines = []
special_characters = ['(', '( ', "'", '"', '|', '[', '“', '【', '【 ', '《', '《 '] # Special characters
for line in lines:
line = line.strip() # Remove leading and trailing spaces
if line: # If the line is not empty
if line[0] in special_characters and len(line) > 1:
# If the first character is special, capitalize the character right after it
capitalized_line = line[0] + line[1].upper() + line[2:]
else:
# If there's no special character, capitalize the first character
capitalized_line = line[0].upper() + line[1:]
capitalized_lines.append(capitalized_line)
else:
capitalized_lines.append(line) # If the line is empty, keep it as is
return '\n'.join(capitalized_lines)
# Function to process and write results from the API
def write_result(response_text, text_path):
# Parse JSON
response_json = json.loads(response_text)
# Get the text content from the 'content' key
raw_content = response_json['data']['content']
# Replace <br> or <p> tags with newline \n
content_with_newline = re.sub(r'<br\s*/?>|</p>', '\n', raw_content)
# Remove HTML tags (span, br, ...) using regex
cleaned_content = re.sub(r'<[^>]+>', '', content_with_newline)
# Apply capitalization processing function
final_content = capitalize_after_newline(cleaned_content)
# Print the processed result
write_file_content(text_path, final_content)
# Function to split the file into smaller chunks
def split_content_into_chunks(content, chunk_size=100):
for i in range(0, len(content), chunk_size):
yield ''.join(content[i:i+chunk_size]) # Join the lines into a string
# Read file content
text_content = read_file_content(raw_path)
# If file is not empty, split the content and send each chunk
if text_content:
for chunk in split_content_into_chunks(text_content):
response = send_api_request(chunk)
if response:
write_result(response, text_path)
you'll have to create your own addonHello guys
I just want to ask that can I customize translate engine to use my own API ?
Here is a translate file python code using my custom API
Python:import requests import re import json # Path to the text file on your computer raw_path = "cntd.txt" text_path = "cntd(translated).txt" # Function to read content from a text file on the computer def read_file_content(file_path): try: with open(file_path, 'r', encoding='utf-8') as file: content = file.readlines() # Read file by line return content except FileNotFoundError: print(f"File {file_path} does not exist.") return None # Function to write content to a file def write_file_content(file_path, content): try: with open(file_path, 'a', encoding='utf-8') as file: file.write(content + "\n") # Add newline after each piece of content print(f"Result has been written to file {file_path}") except Exception as e: print(f"An error occurred while writing to the file: {e}") # Function to send an API request def send_api_request(text_content): url = "https://api.dichnhanh.com/" # Form data you provided # type: "Modern", "Ancient" data = { "type": "Ancient", "enable_analyze": 1, "enable_fanfic": 0, "mode": "qt", "text": text_content, # Text content from file "remove": "" } # Send POST request to API try: response = requests.post(url, data=data) if response.status_code == 200: return response.text else: print(f"Error {response.status_code}: {response.text}") return None except Exception as e: print("An error occurred:", e) return None # Capitalize the first letter immediately after a newline def capitalize_after_newline(text): lines = text.split('\n') # Split text by newline capitalized_lines = [] special_characters = ['(', '( ', "'", '"', '|', '[', '“', '【', '【 ', '《', '《 '] # Special characters for line in lines: line = line.strip() # Remove leading and trailing spaces if line: # If the line is not empty if line[0] in special_characters and len(line) > 1: # If the first character is special, capitalize the character right after it capitalized_line = line[0] + line[1].upper() + line[2:] else: # If there's no special character, capitalize the first character capitalized_line = line[0].upper() + line[1:] capitalized_lines.append(capitalized_line) else: capitalized_lines.append(line) # If the line is empty, keep it as is return '\n'.join(capitalized_lines) # Function to process and write results from the API def write_result(response_text, text_path): # Parse JSON response_json = json.loads(response_text) # Get the text content from the 'content' key raw_content = response_json['data']['content'] # Replace <br> or <p> tags with newline \n content_with_newline = re.sub(r'<br\s*/?>|</p>', '\n', raw_content) # Remove HTML tags (span, br, ...) using regex cleaned_content = re.sub(r'<[^>]+>', '', content_with_newline) # Apply capitalization processing function final_content = capitalize_after_newline(cleaned_content) # Print the processed result write_file_content(text_path, final_content) # Function to split the file into smaller chunks def split_content_into_chunks(content, chunk_size=100): for i in range(0, len(content), chunk_size): yield ''.join(content[i:i+chunk_size]) # Join the lines into a string # Read file content text_content = read_file_content(raw_path) # If file is not empty, split the content and send each chunk if text_content: for chunk in split_content_into_chunks(text_content): response = send_api_request(chunk) if response: write_result(response, text_path)
it actually isn't, but you can export the project to xlsx, csv, etc. just click on the button on the top rightIt's seem to be hard
Otherway,Is there a way to extract all original text to a file
Then I translate this file by my custom API
Then put the translated data to the intial or machine translation column View attachment 4231648
After I translate the text, the small pattern on the left suddenly disappears, how can I restore it?
View attachment 4166512
↑ after
View attachment 4166516
↑ before
[/引用]
你翻译了系统引导字符,假如<New>代表引导使用这个图标,你把New翻译后,引导就无法触发,你在翻译的时候也需要把这个图案文件的名称改为被引导触发的名称才会生效。 "New"只是个举例!
第一个办法,你需要找到并改写图案名字与引导词搭配来触发图案
第二个办法,你再进行一次翻译,跳过关键引导词来维持图案的触发。
Information was shared by a Buddy with the nickname (Alex(GoD)):Sisulizer 4
Thanks, man.You must be registered to see the links
Translator++ v_6.11.27
With the (www\php\cache) folder cleaned out, post it later if you can.Thanks, man.
With the (www\php\cache) folder cleaned out, post it later if you can.
You must be registered to see the links
Translator++ v_6.11.27
Thank you very much.You must be registered to see the links