Skip to content

Latest commit

Β 

History

16 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Localization File Generator

Automated .resx file generator for .NET applications with translation capabilities

.NET Version

Features

  • 🎯 MVC-Optimized
    Built for ASP.NET MVC projects with:
    Controllers/      Views/       Models/
    β”œβ”€ *.cs          β”œβ”€ *.cshtml  └─ DataAnnotations
    
  • πŸ” Automatic Detection
    Scans controllers, views and model validations Scans .cs and .cshtml files for localization patterns
  • 🌐 Multi-language Support
    Generates resource files for en, tr, and custom languages
  • πŸ“‚ Structured Output and Preservation Mirrors your MVC folder hierarchy in Resources/ Creates Resources folders mirroring project structure
  • πŸ”„ Translation API Integration
    Uses MyMemory Translation service for automatic translations
  • ⚠️ Duplicate Prevention
    Ensures unique keys in resource files

Requirements

  • .NET 6.0 SDK or later
  • Internet connection (for translation API)
  • Valid project directory structure

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/localization-generator.git
  2. Navigate to project directory:

    cd localization-generator
  3. Build the solution:

    dotnet build

Usage

Ideal for MVC Projects

Original:
/Controllers/HomeController.cs
/Views/Home/Index.cshtml

Generated:
/Resources/Controllers/HomeController.en.resx
/Resources/Views/Home/Index.tr.resx
  1. Run the generator:

    dotnet run --project LocalizationFileGenerator.csproj
  2. Provide paths when prompted:

    Enter the project path:
    D:\Projects\YourSolution
    
    Enter the output path for .resx files: 
    D:\Projects\YourSolution
    
  3. Generated files will appear in:

    YourSolution/
    └── Resources/
        └── [Mirrored project structure]/
            β”œβ”€β”€ FileName.en.resx
            β”œβ”€β”€ FileName.tr.resx
            └── FileName.resx
    

Configuration

Adding Languages

Modify the languages array in code:

string[] languages = { 
    "",        // Neutral culture
    "en",      // English
    "tr",      // Turkish
    "de"       // Add new languages
};

Data Annotation Support

Format validation attributes:

[Required(ErrorMessageResourceType = typeof(Resources.User),
          ErrorMessageResourceName = "NameRequired")]
public string Name { get; set; }

Translation Process

API Integration

Translation requests use:

string url = $"{baseUrl}get?q={text}&langpair=en|{targetLang}";

Response Handling

if (translationResult?.responseStatus == 200)
{
    return translationResult.TranslatedText;
}
else
{
    return text; // Fallback to original
}

Limitations

  • ⏳ Translation API rate limits (1000/day free tier)
  • πŸ“ Requires consistent project structure
  • πŸ”  First-letter capitalization not preserved

Contributing Guide

Getting Started

  1. Fork the repository
  2. Create a feature branch
  3. Submit a PR with:
    • Description of changes
    • Related issue reference
    • Test results

License

MIT License - See LICENSE for full text


Note: Always test with a sample project before running on production code!

About

Auto-generate localized .resx files from C#/Razor code 🌍 Supports translations, data annotations & structured resources. #DotNet #i18n

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages