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

update turkish translate. #1094

Merged
merged 4 commits into from
Nov 26, 2024
Merged

update turkish translate. #1094

merged 4 commits into from
Nov 26, 2024

Conversation

dsm
Copy link
Collaborator

@dsm dsm commented Nov 25, 2024

Hi, The old translation was quite wrong. I corrected the old translations and replaced the missing ones with machine translations. Since there were too many, I made manual edits. There may be missing and incorrect ones, I will complete them later.

The old translation was quite wrong. I corrected the old translations and replaced the missing ones with machine translations. Since there were too many, I made manual edits. There may be missing and incorrect ones, I will complete them later.
@ra3xdh ra3xdh added this to the 25.1.0 milestone Nov 25, 2024
@dsm
Copy link
Collaborator Author

dsm commented Nov 25, 2024

Python code that I use to translate unfinished translation tag

import os
import xml.etree.ElementTree as ET
import deepl  # Import DeepL API

# Set up DeepL API key
token = 'your_deepL_api_key'  # Replace with your DeepL API key
translator = deepl.Translator(token)

def translate_text(text, source_lang="EN", target_lang="TR"):
    """
    Translates text using DeepL API.
    """
    try:
        # Call DeepL API for translation
        result = translator.translate_text(text, source_lang=source_lang, target_lang=target_lang)
        return result.text
    except Exception as e:
        print(f"Error translating text: {e}")
        return text  # Return the original text in case of an error

def process_ts_file(input_file, output_file):
    """
    Processes a .ts XML file to translate `unfinished` entries.
    """
    tree = ET.parse(input_file)
    root = tree.getroot()

    for context in root.findall("context"):
        for message in context.findall("message"):
            source = message.find("source")
            translation = message.find("translation")
            if translation is not None and translation.get("type") == "unfinished":
                if source is not None:
                    source_text = source.text
                    # Translate the source text
                    translated_text = translate_text(source_text)
                    print(f"Translating: {source_text} -> {translated_text}")
                    translation.text = translated_text
                    translation.attrib.pop("type", None)  # Remove 'unfinished' attribute

    # Save the updated file
    tree.write(output_file, encoding="utf-8", xml_declaration=True)

# Example usage
input_ts_file = "qucs_tr.ts"  # Replace with your input file path
output_ts_file = "qucs_tr_edited.ts"  # Replace with your desired output file path
process_ts_file(input_ts_file, output_ts_file)

@ra3xdh
Copy link
Owner

ra3xdh commented Nov 26, 2024

You can put the Python script in contrib subdirectory.

@ra3xdh ra3xdh merged commit 37da481 into ra3xdh:current Nov 26, 2024
7 checks passed
@ra3xdh
Copy link
Owner

ra3xdh commented Nov 26, 2024

Merged.

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

Successfully merging this pull request may close these issues.

2 participants