Skip to content

Commit

Permalink
C++ Interpreter: Add support for setting the translation domain
Browse files Browse the repository at this point in the history
This maps straight to the Rust API.
  • Loading branch information
tronical committed Feb 22, 2024
1 parent 9f0c3c9 commit fa2cf8c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions api/cpp/include/slint-interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,13 @@ class ComponentCompiler
return s;
}

/// Sets the domain used for translations.
void set_translation_domain(std::string_view domain)
{
cbindgen_private::slint_interpreter_component_compiler_set_translation_domain(
&inner, slint::private_api::string_to_slice(domain));
}

/// Returns the include paths the component compiler is currently configured with.
slint::SharedVector<slint::SharedString> include_paths() const
{
Expand Down
6 changes: 6 additions & 0 deletions api/cpp/tests/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,12 @@ SCENARIO("Component Compiler")
REQUIRE(compiler.style() == "fluent");
}

SECTION("configure translation domain")
{
// Make sure this compiles.
compiler.set_translation_domain("cpptests");
}

SECTION("Compile failure from source")
{
auto result = compiler.build_from_source("Syntax Error!!", "");
Expand Down
10 changes: 10 additions & 0 deletions internal/interpreter/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,16 @@ pub unsafe extern "C" fn slint_interpreter_component_compiler_set_style(
compiler.as_component_compiler_mut().set_style(std::str::from_utf8(&style).unwrap().to_string())
}

#[no_mangle]
pub unsafe extern "C" fn slint_interpreter_component_compiler_set_translation_domain(
compiler: &mut ComponentCompilerOpaque,
translation_domain: Slice<u8>,
) {
compiler
.as_component_compiler_mut()
.set_translation_domain(std::str::from_utf8(&translation_domain).unwrap().to_string())
}

#[no_mangle]
pub unsafe extern "C" fn slint_interpreter_component_compiler_get_style(
compiler: &ComponentCompilerOpaque,
Expand Down

0 comments on commit fa2cf8c

Please sign in to comment.