pub struct SqlxBackend { /* private fields */ }Expand description
Implementations§
Source§impl SqlxBackend
impl SqlxBackend
Sourcepub fn from_translations(
translations: impl IntoIterator<Item = (String, String, String)>,
) -> Self
pub fn from_translations( translations: impl IntoIterator<Item = (String, String, String)>, ) -> Self
Create from an iterator of (locale, key, value) tuples.
This is the core constructor used by all database-specific loaders. You can also call this directly if you have translations from another source.
§Example
use anycms_i18n::Backend;
use anycms_i18n_sqlx::SqlxBackend;
let backend = SqlxBackend::from_translations(vec![
("en".to_string(), "hello".to_string(), "Hello".to_string()),
("zh-CN".to_string(), "hello".to_string(), "你好".to_string()),
]);
assert_eq!(backend.get("en", "hello").as_deref(), Some("Hello"));
assert_eq!(backend.get("zh-CN", "hello").as_deref(), Some("你好"));
assert!(backend.has_locale("en"));
assert!(!backend.has_locale("ja"));Sourcepub fn reload_from_translations(
&self,
translations: impl IntoIterator<Item = (String, String, String)>,
)
pub fn reload_from_translations( &self, translations: impl IntoIterator<Item = (String, String, String)>, )
Async reload: clear the cache and re-populate from an iterator.
This is a convenience wrapper that clears the internal cache and rebuilds it from the provided translations. In practice you would call one of the database-specific reload methods instead.
Trait Implementations§
Source§impl Backend for SqlxBackend
impl Backend for SqlxBackend
Auto Trait Implementations§
impl !RefUnwindSafe for SqlxBackend
impl Freeze for SqlxBackend
impl Send for SqlxBackend
impl Sync for SqlxBackend
impl Unpin for SqlxBackend
impl UnsafeUnpin for SqlxBackend
impl UnwindSafe for SqlxBackend
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
Mutably borrows from an owned value. Read more