Internationalization (i18n) Support

Overview

Bodge now includes full internationalization support with automatic language detection. The system automatically detects your operating system language and displays all messages in the appropriate language.

Supported Languages

How It Works

Automatic Language Detection

The build system automatically detects your system language when it starts:

Windows:

Linux/macOS/Unix:

Manual Language Selection

You can override the automatic detection by modifying the language at runtime (future feature) or by setting your system language.

Examples

English Output

Bodge - The Idiotic Build System

Usage: bodge [command] [target/sequence] [options]

Commands:
  build [target]     - Build specific target (default: all targets)
  fetch              - Fetch git dependencies only
  ...

Chinese Output (中文输出)

Bodge - 简易构建系统

用法:bodge [命令] [目标/序列] [选项]

命令:
  build [目标]       - 构建指定目标(默认:所有目标)
  fetch              - 仅获取git依赖项
  ...

Testing Language Detection

On Windows

  1. To test Chinese:
    # Change Windows display language to Chinese
    # Settings > Time & Language > Language > Windows display language
    # Select "中文(简体,中国)" or similar
    # Restart application
    
  2. To test English:
    # Set display language back to English
    # Restart application
    

On Linux/macOS

  1. To test Chinese:
    export LANG=zh_CN.UTF-8
    ./bodge help
    
  2. To test English:
    export LANG=en_US.UTF-8
    ./bodge help
    

Translation Coverage

All user-facing strings are translated, including:

Application Information

Commands and Help Text

Build Messages

Dependency Management

Error Messages

Warning Messages

Daemon Mode

Architecture

String Management System

src/Strings.h          - String identifiers and API
src/Strings.cpp        - Language detection and translations

Key Components

  1. StringID Enum: Unique identifier for each translatable string
  2. Language Enum: Supported languages
  3. Strings Class: Manages translations and language detection
  4. STR() Macro: Convenient string retrieval

Usage in Code

#include "Strings.h"

// Initialize (called once in main.cpp)
Strings::initialize();

// Get a translated string
std::cout << STR(APP_TITLE) << std::endl;

// Get translated string with variable
std::cout << STR(MSG_TARGET_PLATFORM) << platform.to_string() << std::endl;

Adding New Strings

To add a new translatable string:

  1. Add to StringID enum in Strings.h:
    enum class StringID {
        // ... existing entries
        MY_NEW_STRING,
    };
    
  2. Add translations in Strings.cpp:
    void Strings::load_translations() {
        auto& en = translations_[Language::ENGLISH];
        auto& zh = translations_[Language::CHINESE_SIMPLIFIED];
           
        // ... existing translations
           
        en[StringID::MY_NEW_STRING] = "My English text";
        zh[StringID::MY_NEW_STRING] = "我的中文文本";
    }
    
  3. Use in code:
    std::cout << STR(MY_NEW_STRING) << std::endl;
    

Adding New Languages

To add support for a new language:

  1. Add language to enum in Strings.h:
    enum class Language {
        ENGLISH,
        CHINESE_SIMPLIFIED,
        FRENCH,  // New language
    };
    
  2. Update detection in Strings.cpp:
    Language Strings::detect_system_language() {
        // Add detection logic for new language
        if (lang_str.find("fr_") != std::string::npos) {
            return Language::FRENCH;
        }
    }
    
  3. Add translations in load_translations():
    auto& fr = translations_[Language::FRENCH];
    fr[StringID::APP_TITLE] = "Bodge - Le Système de Construction Idiote";
    // ... add all translations
    

Performance

Best Practices

  1. Always use STR() macro for user-facing strings
  2. Never hardcode user messages in source files
  3. Keep translations consistent in tone and style
  4. Test both languages when adding new features
  5. Use descriptive StringID names for maintainability

Technical Details

Language Detection Priority

  1. Windows: System default LCID
  2. Unix-like: LANG environment variable
  3. Fallback: English (always available)

Thread Safety

The Strings class is thread-safe after initialization:

Encoding

All strings are stored in UTF-8 encoding:

Future Enhancements

Potential future improvements:

Troubleshooting

Chinese characters not displaying correctly

Windows:

# Run the Unicode fix script
.\scripts\fix-console-unicode.bat

Linux/macOS:

# Ensure UTF-8 locale is set
export LANG=zh_CN.UTF-8
export LC_ALL=zh_CN.UTF-8

Language not detected automatically

Check your system language settings:

Fallback to English

If the system language is not Chinese, the system will automatically use English. This is expected behavior and ensures the application always displays readable text.


Example Session

English System

$ ./bodge help
Bodge - The Idiotic Build System

Usage: bodge [command] [target/sequence] [options]

Commands:
  build [target]     - Build specific target (default: all targets)
  fetch              - Fetch git dependencies only
  sequence [name]    - Execute specific sequence
  watch              - Watch mode: automatically rebuild on file changes
  ...

Chinese System (中文系统)

$ ./bodge help
Bodge - 简易构建系统

用法:bodge [命令] [目标/序列] [选项]

命令:
  build [目标]       - 构建指定目标(默认:所有目标)
  fetch              - 仅获取git依赖项
  sequence [名称]    - 执行指定序列
  watch              - 监视模式:文件更改时自动重新构建
  ...