pub struct GettextStore { /* private fields */ }Expand description
In-memory store wrapping a single PO file. All public methods are
async because writes are dispatched to a blocking thread.
Implementations§
Source§impl GettextStore
impl GettextStore
Sourcepub async fn new(
path: impl Into<PathBuf>,
file_store: Arc<dyn FileStore>,
) -> Result<Self, GettextError>
pub async fn new( path: impl Into<PathBuf>, file_store: Arc<dyn FileStore>, ) -> Result<Self, GettextError>
Load (or create empty) a store backed by path via file_store.
Sourcepub async fn loaded_mtime(&self) -> Option<SystemTime>
pub async fn loaded_mtime(&self) -> Option<SystemTime>
mtime observed last read or write, if any.
Sourcepub async fn get(
&self,
msgid: &str,
msgctxt: Option<&str>,
) -> Result<MessageEntry, GettextError>
pub async fn get( &self, msgid: &str, msgctxt: Option<&str>, ) -> Result<MessageEntry, GettextError>
Get a translation entry by (msgid, msgctxt).
Sourcepub async fn list_all(
&self,
) -> Result<Vec<(String, Option<String>, MessageEntry)>, GettextError>
pub async fn list_all( &self, ) -> Result<Vec<(String, Option<String>, MessageEntry)>, GettextError>
List all entries except the header (empty-msgid, no-context).
Sourcepub async fn search(
&self,
query: &str,
limit: Option<usize>,
) -> Result<Vec<MessageEntry>, GettextError>
pub async fn search( &self, query: &str, limit: Option<usize>, ) -> Result<Vec<MessageEntry>, GettextError>
Case-insensitive substring search across msgid + msgstr.
Sourcepub async fn upsert(
&self,
msgid: &str,
msgctxt: Option<&str>,
msgstr: &str,
flags: Option<Vec<String>>,
) -> Result<(), GettextError>
pub async fn upsert( &self, msgid: &str, msgctxt: Option<&str>, msgstr: &str, flags: Option<Vec<String>>, ) -> Result<(), GettextError>
Insert or update a translation. Only msgstr and (optionally)
flags are touched — everything else is preserved.
Sourcepub async fn upsert_full(
&self,
msgid: &str,
msgctxt: Option<&str>,
msgstr: &str,
msgid_plural: Option<&str>,
msgstr_plural: Option<Vec<String>>,
flags: Option<Vec<String>>,
) -> Result<(), GettextError>
pub async fn upsert_full( &self, msgid: &str, msgctxt: Option<&str>, msgstr: &str, msgid_plural: Option<&str>, msgstr_plural: Option<Vec<String>>, flags: Option<Vec<String>>, ) -> Result<(), GettextError>
Extended upsert that also handles plural forms and validates flags.
Sourcepub async fn update_entry(
&self,
msgid: &str,
msgctxt: Option<&str>,
entry: MessageEntry,
) -> Result<(), GettextError>
pub async fn update_entry( &self, msgid: &str, msgctxt: Option<&str>, entry: MessageEntry, ) -> Result<(), GettextError>
Replace an entry wholesale while keeping the key intact. Used by the MCP layer to preserve comments/flags when toggling metadata.
Sourcepub async fn delete(
&self,
msgid: &str,
msgctxt: Option<&str>,
) -> Result<(), GettextError>
pub async fn delete( &self, msgid: &str, msgctxt: Option<&str>, ) -> Result<(), GettextError>
Delete a single (msgid, msgctxt) entry.
Sourcepub async fn delete_by_msgid(&self, msgid: &str) -> Result<usize, GettextError>
pub async fn delete_by_msgid(&self, msgid: &str) -> Result<usize, GettextError>
Delete every entry that uses the given msgid across every
context. Returns the number of entries removed.
Sourcepub async fn metadata(&self) -> Result<IndexMap<String, String>, GettextError>
pub async fn metadata(&self) -> Result<IndexMap<String, String>, GettextError>
Header metadata snapshot.
Sourcepub async fn set_header(
&self,
key: &str,
value: &str,
) -> Result<(), GettextError>
pub async fn set_header( &self, key: &str, value: &str, ) -> Result<(), GettextError>
Set or update a single header. Rejects keys with newlines/colons and values with newlines.
Sourcepub async fn remove_header(&self, key: &str) -> Result<(), GettextError>
pub async fn remove_header(&self, key: &str) -> Result<(), GettextError>
Remove a header. Silently no-ops if the header was not set.
Sourcepub async fn list_languages(&self) -> Result<Vec<String>, GettextError>
pub async fn list_languages(&self) -> Result<Vec<String>, GettextError>
Convenience: report the languages this PO file declares. PO files typically store exactly one language, so this returns at most one element.
Sourcepub async fn add_language(&self, language: &str) -> Result<(), GettextError>
pub async fn add_language(&self, language: &str) -> Result<(), GettextError>
Set the Language header (creating it if absent).
Sourcepub async fn obsolete_entries(&self) -> Result<Vec<MessageEntry>, GettextError>
pub async fn obsolete_entries(&self) -> Result<Vec<MessageEntry>, GettextError>
Parse the preserved obsolete (#~) lines into structured
MessageEntry values.
Obsolete entries are stored verbatim in GettextFile::obsolete_lines
for round-trip fidelity; this method strips the #~ prefix from
each line and runs the rebuilt source through parser::parse_po
so we can surface obsolete entries to callers without disturbing
the serializer.
Sourcepub async fn remove_language(&self, language: &str) -> Result<(), GettextError>
pub async fn remove_language(&self, language: &str) -> Result<(), GettextError>
Remove the Language header, but only if it currently matches the
supplied value. Mismatches return GettextError::InvalidInput.