Skip to main content

Module translator

Module translator 

Source
Expand description

Mod translation and localization support.

This module provides tools for managing translations of mod content, making it easier to localize mods for different languages. It tracks translation status, detects changes in source text, and supports auto-translation from vanilla data.

§Overview

The translation system works by:

  1. Extracting all translatable strings from a pack’s Loc files
  2. Storing translations in a separate JSON file alongside the pack
  3. Tracking which translations need updating when source text changes
  4. Auto-translating from vanilla localisation data where possible

§Translation Files

Translations are stored in separate JSON files. Each file contains all source strings and their translations, along with metadata about translation status.

§Auto-Translation

The system can automatically translate strings that exist in the game’s vanilla localisation files. This is useful for mods that reference vanilla content or use similar terminology.

§Workflow

  1. Create a PackTranslation from a pack
  2. Export to a translation file for external editing
  3. Import completed translations
  4. Generate the final translated Loc file for the pack

§Output

Translated strings are output to a Loc file that overrides the original mod’s entries. The filename depends on the game:

  • Warhammer 1 and newer (except Thrones): !!!!!!translated_locs.loc - loads first due to its naming, allowing translations to override the original entries
  • Thrones of Britannia and older games: localisation.loc

§Example

ⓘ
use rpfm_extensions::translator::PackTranslation;

// Create translation from pack
let mut translation = PackTranslation::new(
    &[translations_path],
    &pack,
    "warhammer_3",
    "EN",  // Source language
    "ES",  // Target language (Spanish)
    &dependencies,
    &english_base,
    &local_fixes,
)?;

// Save translation file
translation.save(&output_path)?;

// Generate translated Loc file for the pack
let loc_file = translation.generate_loc()?;

Modules§

hub
Submission of translations to the Translation Hub.

Structs§

PackTranslation
Translation data for an entire pack.
Translation
Translation entry for a single localizable string.

Constants§

CURRENT_VERSION
Current on-disk format version. New translations default to this; legacy files without a version field are still loaded as v0 and saved back as v0 unless the user opts in to the new format from the UI.
DEFAULT_SRC_LANG
Two-letter source-language code assumed when none is recorded on disk.
TRANSLATED_FILE_NAME
Filename for the generated translated Loc file.
TRANSLATED_PATH
Full path for the translated Loc file within a pack.
TRANSLATED_PATH_OLD
Legacy path for translated Loc files (for backwards compatibility).
VANILLA_LOC_NAME_EN
Name of the Translation Hub’s TSV with the vanilla English texts.