Skip to main content

GettextStore

Struct GettextStore 

Source
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

Source

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.

Source

pub fn path(&self) -> &Path

Path backing this store.

Source

pub async fn loaded_mtime(&self) -> Option<SystemTime>

mtime observed last read or write, if any.

Source

pub async fn get( &self, msgid: &str, msgctxt: Option<&str>, ) -> Result<MessageEntry, GettextError>

Get a translation entry by (msgid, msgctxt).

Source

pub async fn list_all( &self, ) -> Result<Vec<(String, Option<String>, MessageEntry)>, GettextError>

List all entries except the header (empty-msgid, no-context).

Source

pub async fn search( &self, query: &str, limit: Option<usize>, ) -> Result<Vec<MessageEntry>, GettextError>

Case-insensitive substring search across msgid + msgstr.

Source

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.

Source

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.

Source

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.

Source

pub async fn delete( &self, msgid: &str, msgctxt: Option<&str>, ) -> Result<(), GettextError>

Delete a single (msgid, msgctxt) entry.

Source

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.

Source

pub async fn metadata(&self) -> Result<IndexMap<String, String>, GettextError>

Header metadata snapshot.

Source

pub async fn language(&self) -> Result<Option<String>, GettextError>

Language header, if set.

Source

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.

Source

pub async fn remove_header(&self, key: &str) -> Result<(), GettextError>

Remove a header. Silently no-ops if the header was not set.

Source

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.

Source

pub async fn add_language(&self, language: &str) -> Result<(), GettextError>

Set the Language header (creating it if absent).

Source

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.

Source

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.

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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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, 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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,