From 9a6768a3143f2d6f707752ff17970ccba4b36dff Mon Sep 17 00:00:00 2001 From: Ayush Singh Date: Fri, 12 Nov 2021 19:27:08 +0530 Subject: [PATCH] Added more methods for KLocalizedContext. Methods added: 1. setTranslationDomain() 2. translationDomain() --- src/lib.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index e5eee98..af4fbe6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -96,4 +96,43 @@ impl KLocalizedContext { return self->klocalized.get(); }) } + + /// Set Translation Domain for current KLocalizedContext. + /// ```rust + /// use qmetaobject::prelude::*; + /// use ki18n_rs::KLocalizedContext; + /// + /// let mut engine = QmlEngine::new(); + /// let mut context = KLocalizedContext::init_from_engine(&engine); + /// + /// const TRANSLATION_DOMAIN: &str = "Test Domain"; + /// context.set_translation_domain(TRANSLATION_DOMAIN.into()); + /// + /// let domain = context.translation_domain(); + /// + /// assert_eq!(domain, QString::from(TRANSLATION_DOMAIN)); + /// ``` + pub fn set_translation_domain(&mut self, domain: QString) { + cpp!(unsafe [self as "KLocalizedContextHolder *", domain as "QString"] { + self->klocalized->setTranslationDomain(domain); + }) + } + + /// Retrns the current Translation Domain. + /// ```rust + /// use qmetaobject::prelude::*; + /// use ki18n_rs::KLocalizedContext; + /// + /// let mut engine = QmlEngine::new(); + /// let mut context = KLocalizedContext::init_from_engine(&engine); + /// + /// let domain = context.translation_domain(); + /// + /// assert_eq!(domain, QString::from("")); + /// ``` + pub fn translation_domain(&self) -> QString { + cpp!(unsafe [self as "KLocalizedContextHolder *"] -> QString as "QString" { + return self->klocalized->translationDomain(); + }) + } }