Skip to content

Commit ad4eec2

Browse files
committed
Native live preview: Forward the translation domain to fix translations
CC #9942
1 parent dbf9b2b commit ad4eec2

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

api/cpp/include/slint_live_preview.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,12 @@ class LiveReloadingComponent
134134
LiveReloadingComponent(std::string_view file_name, std::string_view component_name,
135135
const slint::SharedVector<slint::SharedString> &include_paths,
136136
const slint::SharedVector<slint::SharedString> &libraries,
137-
std::string_view style)
137+
std::string_view style, std::string_view translation_domain)
138138
{
139139
assert_main_thread();
140140
inner = cbindgen_private::slint_live_preview_new(
141141
string_to_slice(file_name), string_to_slice(component_name), &include_paths,
142-
&libraries, string_to_slice(style));
142+
&libraries, string_to_slice(style), string_to_slice(translation_domain));
143143
}
144144

145145
LiveReloadingComponent(const LiveReloadingComponent &other) : inner(other.inner)

internal/compiler/generator/cpp_live_preview.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,12 @@ fn generate_public_component(
138138
let create_code = vec![
139139
format!("slint::SharedVector<slint::SharedString> include_paths{{ {} }};", compiler_config.include_paths.iter().map(|p| format!("\"{}\"", escape_string(&p.to_string_lossy()))).join(", ")),
140140
format!("slint::SharedVector<slint::SharedString> library_paths{{ {} }};", compiler_config.library_paths.iter().map(|(l, p)| format!("\"{l}={}\"", p.to_string_lossy())).join(", ")),
141-
format!("auto live_preview = slint::private_api::live_preview::LiveReloadingComponent({main_file:?}, {:?}, include_paths, library_paths, \"{}\");", component.name, compiler_config.style.as_ref().unwrap_or(&String::new())),
141+
format!(
142+
"auto live_preview = slint::private_api::live_preview::LiveReloadingComponent({main_file:?}, {:?}, include_paths, library_paths, {:?}, {:?});",
143+
component.name,
144+
compiler_config.style.as_ref().unwrap_or(&String::new()),
145+
compiler_config.translation_domain.as_ref().unwrap_or(&String::new())
146+
),
142147
format!("auto self_rc = vtable::VRc<slint::private_api::ItemTreeVTable, {component_id}>::make(std::move(live_preview));"),
143148
format!("return slint::ComponentHandle<{component_id}>(self_rc);"),
144149
];

internal/compiler/generator/rust_live_preview.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ fn generate_public_component(
171171
let p = p.to_string_lossy();
172172
quote!((#n.to_string(), #p.into()))
173173
});
174+
let translation_domain = compiler_config.translation_domain.iter();
174175
let style = compiler_config.style.iter();
175176

176177
quote!(
@@ -182,6 +183,7 @@ fn generate_public_component(
182183
compiler.set_include_paths([#(#include_paths.into()),*].into_iter().collect());
183184
compiler.set_library_paths([#(#library_paths.into()),*].into_iter().collect());
184185
#(compiler.set_style(#style.to_string());)*
186+
#(compiler.set_translation_domain(#translation_domain.to_string());)*
185187
let instance = sp::live_preview::LiveReloadingComponent::new(compiler, #main_file.into(), #component_name.into())?;
186188
let window_adapter = sp::WindowInner::from_pub(slint::ComponentHandle::window(instance.borrow().instance())).window_adapter();
187189
sp::Ok(Self(instance, window_adapter))

internal/interpreter/live_preview.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ mod ffi {
335335
include_paths: &SharedVector<SharedString>,
336336
library_paths: &SharedVector<SharedString>,
337337
style: Slice<u8>,
338+
translation_domain: Slice<u8>,
338339
) -> *const LiveReloadingComponentInner {
339340
let mut compiler = Compiler::default();
340341
compiler.set_include_paths(
@@ -350,6 +351,10 @@ mod ffi {
350351
if !style.is_empty() {
351352
compiler.set_style(std::str::from_utf8(&style).unwrap().into());
352353
}
354+
if !translation_domain.is_empty() {
355+
compiler
356+
.set_translation_domain(std::str::from_utf8(&translation_domain).unwrap().into());
357+
}
353358
Rc::into_raw(
354359
LiveReloadingComponent::new(
355360
compiler,

0 commit comments

Comments
 (0)