# helixdevsmc/i18n architecture

> Architecture diagram of the GitHub repository helixdevsmc/i18n, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/helixdevsmc/i18n
- Repository: https://github.com/helixdevsmc/i18n

## Overview

##### Project Type and Purpose
- The project is a plugin for Minecraft server environments. Its primary purpose is to perform dynamic translations in-game by intercepting text components and applying locale-specific messages.
- The README outlines usage examples and dependency on ProtocolLib, while the file structure shows platform-specific implementations (Adventure, Paper, Velocity) alongside common core code (API and Common modules). This indicates the project is designed to be modular and adaptable across multiple platforms.

##### File Structure
- Notice the multi-module setup:
- The “api” module defines core interfaces and classes (such as TranslationConsumer, TranslationEntry, TranslationManager, TranslationRepository) that provide the abstraction for internationalization.
- The “common” module contains shared implementations, helper commands (e.g., CommandReloadtranslations), platform abstraction interfaces (I18nPlatform, I18nPlugin), and a FilesTranslationRepository for loading translation files.
- The “adventure”, “paper”, and “velocity” modules house platform-specific implementations, with each providing its own plugin class (e.g., I18nPaperPlugin, I18nVelocityPlugin) and supporting classes such as command senders and ProtocolLib adapters.
- Configuration files such as build.gradle.kts and settings.gradle.kts confirm usage of Gradle for managing dependencies and module builds.

##### README for Additional Insights
- The README clarifies that the plugin supports automatic translation based on client language with specific mention of its integration with ProtocolLib.
- It describes the file structure needed for translations (“i18n_repo”) and provides a sample of how properties files are used.
- It also outlines some limitations and known issues (e.g., translation update timing for items in creative mode).

a. Main Components:
- API Layer: This includes classes like TranslationConsumer, TranslationManager, TranslationEntry, and TranslationRepository which define the translation functionalities.
- Common Module: Implements the API with components such as TranslationManagerImpl, FilesTranslationRepository, command handling (CommandReloadtranslations, Command, Sender), and platform abstraction (I18nPlatform, I18nPlugin).
- Platform-Specific Plugins:
- Adventure Module: Contains the adapter classes (AdventureTranslationConsumer) that integrate with the Adventure platform.
- Paper Module: Provides the I18nPaperPlugin and associated command listeners and ProtocolLib adapter classes.
- Velocity Module: Provides the I18nVelocityPlugin along with its own command implementations.
- External Dependencies: ProtocolLib is used to hook into Minecraft’s text component handling.
- File Loader: A component (referenced in Common and the README) responsible for reading translation files from the “i18n_repo” directory.

b. Relationships and Interactions:
- The API defines interfaces that are implemented in the Common module.
- The Common module acts as a bridge manager between the abstract translation functionalities and the concrete platform-specific modules.
- Platform-specific modules (Adventure, Paper, Velocity) depend on the Common module’s shared functionalities and adapt them to their specific platform needs using their respective plugin classes.
- External systems (i.e., the Minecraft server type corresponding to each module) interact with their plugin’s translation handlers, and these plugins leverage ProtocolLib to intercept text updates.
- The File Loader component interacts with the FilesTranslationRepository to load properties files at runtime.
- Command classes in Common and platform modules receive input (for example, reload commands) and trigger the translation reloading process.

c. Important Architectural Patterns:
- Modularity: Clear separation into API, Common, and Platform-specific modules.
- Abstraction: Use of interfaces in the API layer (e.g., TranslationManager and TranslationRepository) that are implemented differently per module.
- Dependency Injection/Separation of Concerns: The Common module aggregates shared functionalities separate from platform-specific code, easing maintenance and extensibility.
- Adapter Pattern: In Paper and Velocity, adapters (such as BossbarAdapter, ChatAdapter, etc.) allow integration between ProtocolLib’s behavior and the plugin’s translation system.

d. Relevant Technologies, Frameworks, or Libraries:
- Java (as the programming language and platform).
- Gradle (for multi-module build and dependency management).
- ProtocolLib (for intercepting and manipulating Minecraft data packets).
- Adventure API (for handling text components).
- (Implicitly) Minecraft server APIs (Paper, Velocity, Adventure platforms).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Platform Agnostic Core
    subgraph "Platform Agnostic Core"
        subgraph "API Layer"
            API["API Layer<br>(TranslationConsumer, TranslationEntry,<br>TranslationManager, TranslationRepository)"]:::core
        end
        subgraph "Common Module"
            COMMON["Common Core<br>(TranslationManagerImpl)"]:::core
            CMD["CommandReloadtranslations"]:::core
            PLATFORM_AB["Platform Abstraction<br>(I18nPlatform, I18nPlugin)"]:::core
            FILE_LOADER["FilesTranslationRepository"]:::core
            COMMON -->|"triggers"| CMD
            COMMON -->|"provides"| PLATFORM_AB
            COMMON -->|"loads"| FILE_LOADER
        end
        API -->|"implements"| COMMON
    end

    %% Platform-Specific Plugins
    subgraph "Platform-Specific Plugins"
        ADV["Adventure Module<br>(AdventureTranslationConsumer)"]:::platform
        subgraph "Paper Module"
            PAPER["I18nPaperPlugin &<br>Command (BukkitSender)"]:::platform
            PROTO["ProtocolLib Adapters<br>(BossbarAdapter,ChatAdapter,TitleAdapter,etc.)"]:::platform
            PAPER -->|"uses"| PROTO
        end
        subgraph "Velocity Module"
            VELO["I18nVelocityPlugin"]:::platform
            VELO_CMD["Command (VelocitySender)"]:::platform
            VELO -->|"handles"| VELO_CMD
        end
        COMMON -->|"supplies core"| ADV
        COMMON -->|"supplies core"| PAPER
        COMMON -->|"supplies core"| VELO
    end

    %% External Dependencies
    subgraph "External Dependencies"
        MCSrv["Minecraft Server"]:::external
        PLib["ProtocolLib"]:::external
        TRANS["Translation Files<br>(i18n_repo)"]:::external
    end

    %% External Interactions
    COMMON -->|"reads translations from"| TRANS
    PAPER -->|"integrates via"| PLib
    MCSrv -->|"triggers events"| ADV
    MCSrv -->|"triggers events"| PAPER
    MCSrv -->|"triggers events"| VELO

    %% Class Definitions for Colors
    classDef core fill:#cce5ff,stroke:#000,stroke-width:2px;
    classDef platform fill:#d4edda,stroke:#000,stroke-width:2px;
    classDef external fill:#fff3cd,stroke:#000,stroke-width:2px;

    %% Click Events
    click API "https://github.com/helixdevsmc/i18n/tree/main/api/src/main/java/de/helixdevs/i18n/api"
    click COMMON "https://github.com/helixdevsmc/i18n/tree/main/common/src/main/java/de/helixdevs/i18n/common"
    click CMD "https://github.com/helixdevsmc/i18n/blob/main/common/src/main/java/de/helixdevs/i18n/common/command/CommandReloadtranslations.java"
    click PLATFORM_AB "https://github.com/helixdevsmc/i18n/tree/main/common/src/main/java/de/helixdevs/i18n/common/platform"
    click FILE_LOADER "https://github.com/helixdevsmc/i18n/blob/main/common/src/main/java/de/helixdevs/i18n/common/repositories/FilesTranslationRepository.java"
    click ADV "https://github.com/helixdevsmc/i18n/tree/main/adventure/src/main/java/de/helixdevs/i18n/adventure"
    click PAPER "https://github.com/helixdevsmc/i18n/tree/main/paper/src/main/java/de/helixdevs/i18n/paper"
    click PROTO "https://github.com/helixdevsmc/i18n/tree/main/paper/src/main/java/de/helixdevs/i18n/paper/protocollib"
    click VELO "https://github.com/helixdevsmc/i18n/tree/main/velocity/src/main/java/de/helixdevs/i18n/velocity"
    click VELO_CMD "https://github.com/helixdevsmc/i18n/tree/main/velocity/src/main/java/de/helixdevs/i18n/velocity/command"
    click TRANS "https://github.com/helixdevsmc/i18n/tree/main/velocity/i18n_repo"
```
