1.0.3 |
|
---|---|
1.0.2 |
|
0.1.3 |
|
0.1.2 |
|
#11 in #kde
13KB
128 代码行
KI18n Rust crate
KI18n 是一个跨平台国际化框架,被 KDE 应用程序使用。这个 crate 的目的是允许使用 KI18n 与 Rust 和 qmetaobject-rs crate。
要求
此 crate 需要 KF5I18n 已经安装或者至少存在于系统中。
Ubuntu
sudo apt install libkf5i18n-dev
Arch Linux
sudo pacman -S ki18n
KF5I18n 的自定义位置
该 crate 会搜索 KF5I18n,使用环境变量(KF5_I18n_INCLUDE_PATH 和 KF5_I18n_LIBRARY_PATH)如果它们已设置,或者直接搜索在 /usr/include /usr/library
示例
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();
}
依赖
~1.3–2.5MB
~47K SLoC