2021-11-01 10:20:57 +00:00
# KI18n Crate for Rust
2021-11-12 17:46:47 +00:00
[![Crates.io ](https://img.shields.io/crates/v/ki18n-rs )](https://crates.io/crates/ki18n-rs)
2021-11-01 10:20:57 +00:00
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.
2021-12-01 14:09:36 +00:00
# Requirements
This crate requires KF5I18n to be installed or at least present in the system.
## Ubuntu
``` shell
sudo apt install libkf5i18n-dev
```
## Arch Linux
``` shell
sudo pacman -S ki18n
```
# Custom Location for KF5I18n
The crate searches from KF5I18n using either the environment variables (KF5_I18n_INCLUDE_PATH and KF5_I18n_LIBRARY_PATH) if they are set or just
searches at /usr/include /usr/library
2021-11-01 10:20:57 +00:00
# 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();
}
```