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-entrykey/value_original/value_translated/needs_retranslation/removed; noaut, and nosrc_lang,authors,glossaryorversionat the root. The user can opt back into this format from the translator UI to share translations with older tooling.1— current format. Addsversion,src_lang,authors,glossaryandaut, 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
impl PackTranslation
Sourcepub fn relative_path(&self, game_key: &str) -> String
pub fn relative_path(&self, game_key: &str) -> String
Sourcepub fn stats(&self) -> TranslationStats
pub fn stats(&self) -> TranslationStats
Line counts of this translation, ignoring lines removed from the pack.
Sourcepub fn hub_submission(&self, game_key: &str) -> HubSubmission
pub fn hub_submission(&self, game_key: &str) -> HubSubmission
Sourcepub fn submit_to_hub(
&self,
client: &GitHubClient,
hub_owner: &str,
hub_name: &str,
game_key: &str,
content: &str,
) -> Result<SubmissionResult>
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
impl PackTranslation
Sourcepub fn version(&self) -> &u32
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.
Sourcepub fn language(&self) -> &String
pub fn language(&self) -> &String
Target language code for translations (e.g., “ES”, “DE”, “FR”).
Sourcepub fn src_lang(&self) -> &String
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.
Names of the translators who contributed to this translation.
Missing from the old format; defaults to an empty list when loading legacy files.
Sourcepub fn glossary(&self) -> &BTreeMap<String, String>
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.
Sourcepub fn translations(&self) -> &HashMap<String, Translation>
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
impl PackTranslation
Sourcepub fn version_mut(&mut self) -> &mut u32
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.
Sourcepub fn language_mut(&mut self) -> &mut String
pub fn language_mut(&mut self) -> &mut String
Target language code for translations (e.g., “ES”, “DE”, “FR”).
Sourcepub fn src_lang_mut(&mut self) -> &mut String
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.
Sourcepub fn pack_name_mut(&mut self) -> &mut String
pub fn pack_name_mut(&mut self) -> &mut String
Name of the pack these translations belong to.
Names of the translators who contributed to this translation.
Missing from the old format; defaults to an empty list when loading legacy files.
Sourcepub fn glossary_mut(&mut self) -> &mut BTreeMap<String, String>
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.
Sourcepub fn translations_mut(&mut self) -> &mut HashMap<String, Translation>
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
impl PackTranslation
Sourcepub fn set_version(&mut self, val: u32) -> &mut Self
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.
Sourcepub fn set_language(&mut self, val: String) -> &mut Self
pub fn set_language(&mut self, val: String) -> &mut Self
Target language code for translations (e.g., “ES”, “DE”, “FR”).
Sourcepub fn set_src_lang(&mut self, val: String) -> &mut Self
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.
Sourcepub fn set_pack_name(&mut self, val: String) -> &mut Self
pub fn set_pack_name(&mut self, val: String) -> &mut Self
Name of the pack these translations belong to.
Names of the translators who contributed to this translation.
Missing from the old format; defaults to an empty list when loading legacy files.
Sourcepub fn set_glossary(&mut self, val: BTreeMap<String, String>) -> &mut Self
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.
Sourcepub fn set_translations(
&mut self,
val: HashMap<String, Translation>,
) -> &mut Self
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
impl PackTranslation
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>
pub fn sort_and_merge_locs_for_translation(locs: &mut [&RFile]) -> Result<Loc>
Sourcepub fn vanilla_loc_file_name(src_lang: &str) -> String
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.
Sourcepub fn generate_vanilla_loc(
game: &GameInfo,
game_path: &Path,
src_lang: &str,
dest_folder: &Path,
) -> Result<bool>
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.
Sourcepub fn apply(&self, _pack: &mut Pack) -> Result<()>
pub fn apply(&self, _pack: &mut Pack) -> Result<()>
This function applies a PackTranslation to a Pack.
Sourcepub fn load(
paths: &[PathBuf],
pack_name: &str,
game_key: &str,
src_lang: &str,
language: &str,
) -> Result<Self>
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.
Sourcepub fn file_name(&self) -> String
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.
Sourcepub fn save(&mut self, path: &Path, game_key: &str) -> Result<()>
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.
pub fn definition() -> Definition
pub fn from_table(&mut self, table: &TableInMemory) -> Result<()>
pub fn to_table(&self) -> Result<TableInMemory>
Sourcepub fn glossary_definition() -> Definition
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.
Sourcepub fn glossary_to_table(&self) -> Result<TableInMemory>
pub fn glossary_to_table(&self) -> Result<TableInMemory>
Materialize the glossary as an editable TableInMemory for the UI.
Sourcepub fn glossary_from_table(&mut self, table: &TableInMemory) -> Result<()>
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
impl Clone for PackTranslation
Source§fn clone(&self) -> PackTranslation
fn clone(&self) -> PackTranslation
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PackTranslation
impl Debug for PackTranslation
Source§impl Default for PackTranslation
impl Default for PackTranslation
Source§impl<'de> Deserialize<'de> for PackTranslation
impl<'de> Deserialize<'de> for PackTranslation
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for PackTranslation
impl RefUnwindSafe for PackTranslation
impl Send for PackTranslation
impl Sync for PackTranslation
impl Unpin for PackTranslation
impl UnsafeUnpin for PackTranslation
impl UnwindSafe for PackTranslation
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreimpl<T> MaybeSend for T
impl<T> MaybeSync for T
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.