Skip to main content

PackTranslation

Struct PackTranslation 

Source
pub struct PackTranslation { /* private fields */ }
Expand description

Translation data for an entire pack.

Contains all translatable strings from a pack along with their translations and metadata about translation status.

§Persistence and Format Versioning

This struct is serialized to JSON files for storage. There are currently two on-disk formats, picked by the version field:

  • 0 — legacy format. Per-entry key/value_original/value_translated/ needs_retranslation/removed; no aut, and no src_lang, authors, glossary or version at the root. The user can opt back into this format from the translator UI to share translations with older tooling.
  • 1 — current format. Adds version, src_lang, authors, glossary and aut, and uses the shorter per-entry field names (src/dst/retr/rem/aut).

On load, files without a version field are treated as v0 — i.e. existing translation hubs and legacy local files keep their format unless the user explicitly upgrades them.

§Parent Translations

When a pack has dependencies, translations from parent mods are also loaded and used for auto-translation, ensuring consistent terminology across dependent mods.

Implementations§

Source§

impl PackTranslation

Source

pub fn relative_path(&self, game_key: &str) -> String

Path of this translation’s file, relative to a translations folder or the hub’s root.

§Arguments
  • game_key - Key of the game the translation belongs to.
§Returns

{game_key}/{pack_name}/{file_name}, with / separators so it’s also valid as a repository path.

Source

pub fn stats(&self) -> TranslationStats

Line counts of this translation, ignoring lines removed from the pack.

Source

pub fn hub_submission(&self, game_key: &str) -> HubSubmission

Build the submission of this translation to the Translation Hub.

§Arguments
  • game_key - Key of the game the translation belongs to.
§Returns

The paths, branch and texts of the submission.

Source

pub fn submit_to_hub( &self, client: &GitHubClient, hub_owner: &str, hub_name: &str, game_key: &str, content: &str, ) -> Result<SubmissionResult>

Submit this translation to the Translation Hub as a pull request, or update its open one.

The commit goes on top of the hub’s current default branch, in the hub itself if the user can push to it, or in the user’s fork otherwise (created if needed). Each submission replaces the previous one in the translation’s branch, so an open pull request always shows a single commit.

§Arguments
  • client - GitHub client, signed in as the submitting user.
  • hub_owner - Owner of the Translation Hub repository.
  • hub_name - Name of the Translation Hub repository.
  • game_key - Key of the game the translation belongs to.
  • content - Contents of the translation’s file, as saved on disk.
§Returns

The pull request’s page, and whether it was newly opened.

§Errors

Returns an error if the hub can’t be found, the fork isn’t ready in time, or any GitHub request fails.

Source§

impl PackTranslation

Source

pub fn version(&self) -> &u32

On-disk format version. See the struct-level docs for the meaning of each value. New in-memory translations default to v1; legacy files without this field are treated as v0.

Source

pub fn language(&self) -> &String

Target language code for translations (e.g., “ES”, “DE”, “FR”).

Source

pub fn src_lang(&self) -> &String

Source language code these translations are based on (e.g., “EN”).

Missing from the old format; defaults to DEFAULT_SRC_LANG when loading legacy files.

Source

pub fn pack_name(&self) -> &String

Name of the pack these translations belong to.

Source

pub fn authors(&self) -> &Vec<String>

Names of the translators who contributed to this translation.

Missing from the old format; defaults to an empty list when loading legacy files.

Source

pub fn glossary(&self) -> &BTreeMap<String, String>

Per-pack glossary of preferred translations for specific source terms.

Stored as a sorted map (source term → preferred translation) so the JSON output is deterministic. v1+ only; dropped when saving as v0.

Source

pub fn translations(&self) -> &HashMap<String, Translation>

Map of Loc keys to their translation data.

Keys are the original Loc entry keys from the pack.

Source§

impl PackTranslation

Source

pub fn version_mut(&mut self) -> &mut u32

On-disk format version. See the struct-level docs for the meaning of each value. New in-memory translations default to v1; legacy files without this field are treated as v0.

Source

pub fn language_mut(&mut self) -> &mut String

Target language code for translations (e.g., “ES”, “DE”, “FR”).

Source

pub fn src_lang_mut(&mut self) -> &mut String

Source language code these translations are based on (e.g., “EN”).

Missing from the old format; defaults to DEFAULT_SRC_LANG when loading legacy files.

Source

pub fn pack_name_mut(&mut self) -> &mut String

Name of the pack these translations belong to.

Source

pub fn authors_mut(&mut self) -> &mut Vec<String>

Names of the translators who contributed to this translation.

Missing from the old format; defaults to an empty list when loading legacy files.

Source

pub fn glossary_mut(&mut self) -> &mut BTreeMap<String, String>

Per-pack glossary of preferred translations for specific source terms.

Stored as a sorted map (source term → preferred translation) so the JSON output is deterministic. v1+ only; dropped when saving as v0.

Source

pub fn translations_mut(&mut self) -> &mut HashMap<String, Translation>

Map of Loc keys to their translation data.

Keys are the original Loc entry keys from the pack.

Source§

impl PackTranslation

Source

pub fn set_version(&mut self, val: u32) -> &mut Self

On-disk format version. See the struct-level docs for the meaning of each value. New in-memory translations default to v1; legacy files without this field are treated as v0.

Source

pub fn set_language(&mut self, val: String) -> &mut Self

Target language code for translations (e.g., “ES”, “DE”, “FR”).

Source

pub fn set_src_lang(&mut self, val: String) -> &mut Self

Source language code these translations are based on (e.g., “EN”).

Missing from the old format; defaults to DEFAULT_SRC_LANG when loading legacy files.

Source

pub fn set_pack_name(&mut self, val: String) -> &mut Self

Name of the pack these translations belong to.

Source

pub fn set_authors(&mut self, val: Vec<String>) -> &mut Self

Names of the translators who contributed to this translation.

Missing from the old format; defaults to an empty list when loading legacy files.

Source

pub fn set_glossary(&mut self, val: BTreeMap<String, String>) -> &mut Self

Per-pack glossary of preferred translations for specific source terms.

Stored as a sorted map (source term → preferred translation) so the JSON output is deterministic. v1+ only; dropped when saving as v0.

Source

pub fn set_translations( &mut self, val: HashMap<String, Translation>, ) -> &mut Self

Map of Loc keys to their translation data.

Keys are the original Loc entry keys from the pack.

Source§

impl PackTranslation

Source

pub fn new( paths: &[PathBuf], pack: &Pack, game_key: &str, src_lang: &str, language: &str, dependencies: &Dependencies, base_english: &HashMap<String, String>, base_local_fixes: &HashMap<String, String>, ) -> Result<Self>

Source

pub fn sort_and_merge_locs_for_translation(locs: &mut [&RFile]) -> Result<Loc>

Source

pub fn vanilla_loc_file_name(src_lang: &str) -> String

Name of the TSV with the vanilla texts of a source language.

§Arguments
  • src_lang - Source language code (e.g. “EN”, “SP”).
§Returns

VANILLA_LOC_NAME_EN for English, vanilla_{src_lang}.tsv for any other language.

Source

pub fn generate_vanilla_loc( game: &GameInfo, game_path: &Path, src_lang: &str, dest_folder: &Path, ) -> Result<bool>

Generates the vanilla texts TSV of a language from the game’s locale packs.

The file is kept so it can still be used after the game stops shipping that language, and it’s only regenerated when the locale packs are newer than it.

§Arguments
  • game - Game the locale packs belong to.
  • game_path - Path of the game’s installation.
  • src_lang - Language code of the locale packs to read (e.g. “SP”).
  • dest_folder - Folder where the TSV is written.
§Returns

true if the game has locale packs for the language (so the TSV is up to date), false otherwise.

§Errors

Returns an error if the game’s data folder can’t be read, or if the packs can’t be read or the TSV written.

Source

pub fn apply(&self, _pack: &mut Pack) -> Result<()>

This function applies a PackTranslation to a Pack.

Source

pub fn load( paths: &[PathBuf], pack_name: &str, game_key: &str, src_lang: &str, language: &str, ) -> Result<Self>

This function loads a PackTranslation to memory from either a local json file, or a remote one.

Files written in the old format (with key, value_original, value_translated, needs_retranslation, removed and without src_lang/authors/glossary/aut) are accepted transparently via serde aliases and field defaults — no explicit version probing needed.

On-disk layout:

  • v1+ → {game_key}/{pack_name}/{src_lang}-{language}.json.
  • v0 → {game_key}/{pack_name}/{language}.json (no source language in the path, since v0 implicitly assumed English).

load_json will probe both paths in that order so users who upgrade RPFM keep finding their existing translations even if they were saved before this refactor.

Source

pub fn file_name(&self) -> String

Name of the file this translation is saved as, which depends on its format version.

§Returns

{src_lang}-{language}.json for v1+, or the legacy {language}.json for v0.

Source

pub fn save(&mut self, path: &Path, game_key: &str) -> Result<()>

This function saves a PackTranslation from memory to a .json file with the provided path.

The on-disk format depends on Self::version: 0 writes the legacy shape, 1 (or higher) writes the current shape. Downgrading v1 → v0 drops fields that don’t exist in v0 (src_lang, authors, glossary and the per-entry aut flag).

The filename also depends on the version: v1+ uses {src_lang}-{language}.json so translations from different source languages live side-by-side; v0 keeps the legacy {language}.json because the old format had no concept of source language.

Source

pub fn definition() -> Definition

Source

pub fn from_table(&mut self, table: &TableInMemory) -> Result<()>

Source

pub fn to_table(&self) -> Result<TableInMemory>

Source

pub fn glossary_definition() -> Definition

Definition of the per-pack glossary table, used to drive the UI table view.

The glossary is a flat two-column table: a source term (used as the key) and the preferred translation for it.

Source

pub fn glossary_to_table(&self) -> Result<TableInMemory>

Materialize the glossary as an editable TableInMemory for the UI.

Source

pub fn glossary_from_table(&mut self, table: &TableInMemory) -> Result<()>

Replace the glossary with the contents of table. Empty source cells are dropped so a trailing blank row left over from the UI doesn’t end up in the saved JSON.

Trait Implementations§

Source§

impl Clone for PackTranslation

Source§

fn clone(&self) -> PackTranslation

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PackTranslation

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PackTranslation

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for PackTranslation

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for PackTranslation

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> MaybeSend for T

§

impl<T> MaybeSync for T

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more