Added Methods for KLocalizedString.

This commit is contained in:
Ayush Singh 2021-12-15 21:37:05 +05:30
parent 736d5c5a26
commit 4c2f78d2bb
3 changed files with 46 additions and 0 deletions

View file

@ -15,6 +15,8 @@ build = "build.rs"
cpp = "0.5" cpp = "0.5"
qmetaobject = "0.2" qmetaobject = "0.2"
qttypes = "0.2" qttypes = "0.2"
# qmetaobject = { path="../qmetaobject-rs/qmetaobject" }
# qttypes = { path="../qmetaobject-rs/qttypes" }
[build-dependencies] [build-dependencies]
cpp_build = "0.5" cpp_build = "0.5"

View file

@ -37,4 +37,45 @@ impl KLocalizedString {
return KLocalizedString::applicationDomain(); return KLocalizedString::applicationDomain();
}) })
} }
/// Get the languages for which translations will be made.
/// Returned languages are ordered with decreasing priority.
pub fn languages() -> QStringList {
cpp!(unsafe [] -> QStringList as "QStringList" {
return KLocalizedString::languages();
})
}
/// Set the languages for which translations will be made.
/// This overrides the languages provided by the locale. Languages should be ordered with decreasing priority.
/// TODO: Add Test
pub fn set_languages(languages: &QStringList) {
cpp!(unsafe [languages as "QStringList"] {
KLocalizedString::setLanguages(languages);
});
}
/// Clear override languages.
/// This clears the override languages, going back to those provided by the locale.
/// TODO: Add Test.
pub fn clear_languages() {
cpp!(unsafe [] {
KLocalizedString::clearLanguages();
})
}
/// Load locales for a domain from a specific location.
/// This is useful for resources which have their translation files outside of the usual $XDG_DATA_DIRS/locales location.
pub fn add_domain_locale_dir(domain: QByteArray, path: QString) {
cpp!(unsafe [domain as "QByteArray", path as "QString"] {
KLocalizedString::addDomainLocaleDir(domain, path);
})
}
/// Check whether the translation catalog file in the given language for the set application translation domain exists.
pub fn is_application_translated_into(language: &QString) -> bool {
cpp!(unsafe [language as "QString"] -> bool as "bool" {
return KLocalizedString::isApplicationTranslatedInto(language);
})
}
} }

View file

@ -11,3 +11,6 @@ fn application_domain() {
assert_eq!(domain.to_str().unwrap(), "KI18n"); assert_eq!(domain.to_str().unwrap(), "KI18n");
} }
#[test]
fn languages() {}