Improved Documentation
Added some doc tests as examples.
This commit is contained in:
parent
cb934ff6dc
commit
57fefcc945
|
@ -22,6 +22,14 @@ cpp_class!(
|
||||||
|
|
||||||
impl KLocalizedContext {
|
impl KLocalizedContext {
|
||||||
/// Initialize KLocalizedContext from Engine.
|
/// Initialize KLocalizedContext from Engine.
|
||||||
|
/// #Example
|
||||||
|
/// ```
|
||||||
|
/// use ki18n_rs::klocalizedcontext::KLocalizedContext;
|
||||||
|
/// use qmetaobject::prelude::*;
|
||||||
|
///
|
||||||
|
/// let engine = QmlEngine::new();
|
||||||
|
/// KLocalizedContext::init_from_engine(&engine);
|
||||||
|
/// ```
|
||||||
pub fn init_from_engine(engine: &QmlEngine) -> Self {
|
pub fn init_from_engine(engine: &QmlEngine) -> Self {
|
||||||
let engine_ptr = engine.cpp_ptr();
|
let engine_ptr = engine.cpp_ptr();
|
||||||
cpp!(unsafe [engine_ptr as "QQmlEngine*"] -> KLocalizedContext as "KLocalizedContextHolder" {
|
cpp!(unsafe [engine_ptr as "QQmlEngine*"] -> KLocalizedContext as "KLocalizedContextHolder" {
|
||||||
|
@ -40,6 +48,15 @@ impl KLocalizedContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set Translation Domain for current KLocalizedContext.
|
/// Set Translation Domain for current KLocalizedContext.
|
||||||
|
/// # Example
|
||||||
|
/// ```
|
||||||
|
/// use ki18n_rs::klocalizedcontext::KLocalizedContext;
|
||||||
|
/// use qmetaobject::prelude::*;
|
||||||
|
///
|
||||||
|
/// let engine = QmlEngine::new();
|
||||||
|
/// let mut context = KLocalizedContext::init_from_engine(&engine);
|
||||||
|
/// context.set_translation_domain("Test Domain".into());
|
||||||
|
/// ```
|
||||||
pub fn set_translation_domain(&mut self, domain: QString) {
|
pub fn set_translation_domain(&mut self, domain: QString) {
|
||||||
cpp!(unsafe [self as "KLocalizedContextHolder *", domain as "QString"] {
|
cpp!(unsafe [self as "KLocalizedContextHolder *", domain as "QString"] {
|
||||||
self->klocalized->setTranslationDomain(domain);
|
self->klocalized->setTranslationDomain(domain);
|
||||||
|
|
|
@ -16,6 +16,14 @@ cpp_class!(
|
||||||
|
|
||||||
impl KLocalizedString {
|
impl KLocalizedString {
|
||||||
/// Set Application Domain
|
/// Set Application Domain
|
||||||
|
/// # Example
|
||||||
|
/// ```
|
||||||
|
/// use std::ffi::CString;
|
||||||
|
/// use ki18n_rs::prelude::KLocalizedString;
|
||||||
|
///
|
||||||
|
/// let domain = CString::new("Application_Domain").unwrap();
|
||||||
|
/// KLocalizedString::set_application_domain(&domain);
|
||||||
|
/// ```
|
||||||
pub fn set_application_domain(domain: &CStr) {
|
pub fn set_application_domain(domain: &CStr) {
|
||||||
let domain_ptr = domain.as_ptr();
|
let domain_ptr = domain.as_ptr();
|
||||||
cpp!(unsafe [domain_ptr as "char*"] {
|
cpp!(unsafe [domain_ptr as "char*"] {
|
||||||
|
|
|
@ -2,14 +2,6 @@ use ki18n_rs::klocalizedcontext::KLocalizedContext;
|
||||||
use qmetaobject::prelude::*;
|
use qmetaobject::prelude::*;
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn init_engine() {
|
|
||||||
let _lock = common::lock_for_test();
|
|
||||||
|
|
||||||
let engine = QmlEngine::new();
|
|
||||||
KLocalizedContext::init_from_engine(&engine);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cpp_ptr() {
|
fn cpp_ptr() {
|
||||||
let _lock = common::lock_for_test();
|
let _lock = common::lock_for_test();
|
||||||
|
|
|
@ -8,7 +8,6 @@ fn application_domain() {
|
||||||
|
|
||||||
KLocalizedString::set_application_domain(&domain);
|
KLocalizedString::set_application_domain(&domain);
|
||||||
let domain = KLocalizedString::application_domain();
|
let domain = KLocalizedString::application_domain();
|
||||||
println!("{:#?}", domain);
|
|
||||||
|
|
||||||
assert_eq!(domain.to_str().unwrap(), "KI18n");
|
assert_eq!(domain.to_str().unwrap(), "KI18n");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue