From c1b374e09ba83df831104152471c344312e8b8b9 Mon Sep 17 00:00:00 2001 From: Ayush Singh Date: Mon, 1 Nov 2021 18:02:04 +0530 Subject: [PATCH] Added Documentation. Almost ready for publishing in crates.io. --- Cargo.toml | 2 ++ src/lib.rs | 54 +++++++++++++++++++++++++++++++++++++++++++++++++- tests/tests.rs | 7 ------- 3 files changed, 55 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2ff0572..167644e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,7 @@ [package] name = "ki18n-rs" +description = "A crate to use KF5I18n from rust." +author = ["Ayush Singh "] version = "0.1.0" edition = "2018" links = "KF5I18n" diff --git a/src/lib.rs b/src/lib.rs index 441db71..10284c0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,44 @@ +//! # KI18n-rs +//! KI18n is a cross-platform internationalization framework used by KDE applications. This crate is meant to allow using KI18n with +//! Rust and [qmetaobject-rs](https://github.com/woboq/qmetaobject-rs) crate. +//! # Example +//! ```rust +//! use cstr::cstr; +//! use qmetaobject::prelude::*; +//! use ki18n_rs::KLocalizedContext; +//! +//! fn main() { +//! let mut engine = QmlEngine::new(); +//! KLocalizedContext::init_from_engine(&engine); +//! engine.load_data(r#" +//! import QtQuick 2.6 +//! import QtQuick.Controls 2.0 as Controls +//! import QtQuick.Layouts 1.2 +//! import org.kde.kirigami 2.13 as Kirigami +//! +//! // Base element, provides basic features needed for all kirigami applications +//! Kirigami.ApplicationWindow { +//! // ID provides unique identifier to reference this element +//! id: root +//! +//! // Window title +//! // i18nc is useful for adding context for translators, also lets strings be changed for different languages +//! title: i18nc("@title:window", "Hello World") +//! +//! // Initial page to be loaded on app load +//! pageStack.initialPage: Kirigami.Page { +//! +//! Controls.Label { +//! // Center label horizontally and vertically within parent element +//! anchors.centerIn: parent +//! text: i18n("Hello World!") +//! } +//! } +//! } +//! "#.into()); +//! engine.exec(); +//! } +//! ``` use cpp::{cpp, cpp_class}; use qmetaobject::prelude::*; use qmetaobject::QObjectPinned; @@ -15,9 +56,20 @@ cpp! {{ }; }} -cpp_class!(pub unsafe struct KLocalizedContext as "KLocalizedContextHolder"); +cpp_class!( + /// Struct representing KLocalizedContext. Mainly used with QML. + pub unsafe struct KLocalizedContext as "KLocalizedContextHolder" +); impl KLocalizedContext { + /// Initialize KLocalizedContext from Engine. + /// ```rust + /// use qmetaobject::prelude::*; + /// use ki18n_rs::KLocalizedContext; + /// + /// let mut engine = QmlEngine::new(); + /// KLocalizedContext::init_from_engine(&engine); + /// ``` pub fn init_from_engine(engine: &QmlEngine) { let engine_ptr = engine.cpp_ptr(); cpp!(unsafe [engine_ptr as "QQmlEngine*"] { diff --git a/tests/tests.rs b/tests/tests.rs index 09db8a9..344f078 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1,8 +1 @@ use ki18n_rs::*; -use qmetaobject::prelude::*; - -#[test] -fn test_klocalized_init() { - let mut engine = QmlEngine::new(); - KLocalizedContext::init_from_engine(&engine); -}