7 个稳定版本
2.0.1 |
|
---|---|
2.0.0 |
|
1.2.0 | 2022 年 2 月 4 日 |
1.1.1 | 2022 年 1 月 10 日 |
1.0.6 | 2021 年 12 月 23 日 |
在 国际化(i18n) 中排名 133
每月下载 33 次
20KB
237 代码行
Rust 的 KI18n Crate
简介
KI18n 是一个跨平台国际化框架,被 KDE 应用程序使用。这个 crate 的目的是允许使用 KI18n 和 Rust 以及 qmetaobject-rs crate。
动机
我爱 KDE。我已经很长时间将其作为我的主要桌面环境。我也喜欢 Rust 编程语言。目前,如果没有一些 C++ FFI,几乎不可能从 Rust 使用任何 KDE 框架。虽然 FFI 从来都不容易,但由于 C++ 的面向对象特性,其复杂性与普通的 C 相比呈指数级增长,这与 Rust 的某种函数式设计完全不同。
如果可能的话,我希望一级 KDE 框架能够以一种较为自然的方式从实用主义 Rust 中使用。我现在对可以使用 QML 的 KDE 框架很感兴趣。
要求
此 crate 需要 KF5I18n 已安装或至少存在于系统中。
Ubuntu
sudo apt install libkf5i18n-dev
Arch Linux
sudo pacman -S ki18n
KF5I18n 的自定义位置
此 crate 使用环境变量(KF_VERSION
、KF_INCLUDE_PATH
和 KF_LIBRARY_PATH
)从 KF5I18n 中搜索,如果它们已设置,则使用 kf5-config
来查找路径。
功能
qmetaobject
:启用一些需要 qmetaobject 的方法。大多数人需要这个。
示例
use cstr::cstr;
use qmetaobject::prelude::*;
use ki18n::klocalizedcontext::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();
}
```rust
依赖
~1–2.2MB
~42K SLoC