Added Documentation.
Almost ready for publishing in crates.io.
This commit is contained in:
parent
0c350fc91c
commit
c1b374e09b
|
@ -1,5 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "ki18n-rs"
|
name = "ki18n-rs"
|
||||||
|
description = "A crate to use KF5I18n from rust."
|
||||||
|
author = ["Ayush Singh <ayushdevel1325@gmail.com>"]
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
links = "KF5I18n"
|
links = "KF5I18n"
|
||||||
|
|
54
src/lib.rs
54
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 cpp::{cpp, cpp_class};
|
||||||
use qmetaobject::prelude::*;
|
use qmetaobject::prelude::*;
|
||||||
use qmetaobject::QObjectPinned;
|
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 {
|
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) {
|
pub fn init_from_engine(engine: &QmlEngine) {
|
||||||
let engine_ptr = engine.cpp_ptr();
|
let engine_ptr = engine.cpp_ptr();
|
||||||
cpp!(unsafe [engine_ptr as "QQmlEngine*"] {
|
cpp!(unsafe [engine_ptr as "QQmlEngine*"] {
|
||||||
|
|
|
@ -1,8 +1 @@
|
||||||
use ki18n_rs::*;
|
use ki18n_rs::*;
|
||||||
use qmetaobject::prelude::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_klocalized_init() {
|
|
||||||
let mut engine = QmlEngine::new();
|
|
||||||
KLocalizedContext::init_from_engine(&engine);
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue