Added Documentation.

Almost ready for publishing in crates.io.
This commit is contained in:
Ayush Singh 2021-11-01 18:02:04 +05:30
parent 0c350fc91c
commit c1b374e09b
3 changed files with 55 additions and 8 deletions

View file

@ -1,5 +1,7 @@
[package]
name = "ki18n-rs"
description = "A crate to use KF5I18n from rust."
author = ["Ayush Singh <ayushdevel1325@gmail.com>"]
version = "0.1.0"
edition = "2018"
links = "KF5I18n"

View file

@ -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*"] {

View file

@ -1,8 +1 @@
use ki18n_rs::*;
use qmetaobject::prelude::*;
#[test]
fn test_klocalized_init() {
let mut engine = QmlEngine::new();
KLocalizedContext::init_from_engine(&engine);
}