Skip to content

C# Console Application that automatically translates missing .resx entries in your localization files using Microsoft Azure Cognitive Translator API

License

Notifications You must be signed in to change notification settings

nathenxbrewer/ResxTranslator.Console

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📄 ResxTranslator.Console

ResxTranslatorConsoleApp is a C# Console Application that automatically translates missing .resx entries in your localization files using Microsoft Azure Cognitive Translator API. The app scans a directory for .resx files, compares the default file with language-specific files, and fills in the missing translations.

This tool is ideal for automating translations in applications with multi-language support.


🚀 Features

  • 📂 Directory scanning for .resx files.
  • 🔍 Detects missing translations in language-specific .resx files.
  • 🤖 Uses Microsoft Azure Translator API for high-quality translations.
  • 🔄 Overwrites existing language files with newly translated entries.
  • 📝 Supports command-line arguments to customize behavior.
  • 🛠️ Dry-run mode for testing without making changes.
  • 📊 Logging of translated entries.

📦 How It Works

  1. The app scans the specified directory for .resx files.
  2. It identifies the default .resx file (e.g., AppResource.resx).
  3. It detects language-specific files (e.g., AppResource.fr.resx, AppResource.es.resx).
  4. The app compares the default file with each language file to find missing translations.
  5. It uses Microsoft Azure Translator API to fill in the missing translations.
  6. The app saves the updated language files in the same directory.

🔧 Installation and Setup

  1. Clone the repository:

    git clone https://github.com/your-username/ResxTranslator.Console.git
    cd ResxTranslator.Console
  2. Add your Microsoft Azure API key:

    • Go to Azure Portal.
    • Navigate to your Cognitive Services resource.
    • Copy your API key and region.

🏗 Building the Project

Run the following command to build the project:

dotnet build

💻 Usage

Run the app with the following command:

dotnet run --dir "/path/to/resx/files" --default AppResource --languages "languages.txt" --log

📝 Command-Line Arguments

Argument Description
--dir Required. Directory containing the .resx files.
--default Required. The default .resx file name (without .resx).
--languages Optional. Path to a text file listing languages to translate. If not provided, the app will translate using the existing .resx files in the directory specified.
--dry-run Optional. Show what would be translated without making changes.
--log Optional. Enable logging of translated entries.

📋 Example Directory Structure

/resx
 ┣ AppResource.resx
 ┣ AppResource.fr.resx
 ┣ AppResource.es.resx
 ┣ ProductNames.resx
 ┣ ProductNames.fr.resx
 ┣ ProductNames.es.resx
 ┗ languages.txt

📄 Example languages.txt File

fr
es
de
it

Examples

Example 1: Translating Missing Entries

dotnet run --dir "/path/to/resx/files" --default AppResource --log

Example 2: Using a Language File

dotnet run --dir "/path/to/resx/files" --default ProductNames --languages "languages.txt" --dry-run

📚 Dependencies

  • .NET 7.0
  • Microsoft Azure Cognitive Translator API
  • Newtonsoft.Json

📜 License

This project is licensed under the MIT License. See the LICENSE file for more details.


❤️ Support My Work

If you find this project helpful, consider buying me a coffee! It helps keep me motivated to create more awesome tools. 😊

Buy Me A Coffee

About

C# Console Application that automatically translates missing .resx entries in your localization files using Microsoft Azure Cognitive Translator API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages