Skip to content

Commit d9700b8

Browse files
committed
i18n: conditionally load SELinux locale strings based on feature flag
1 parent 2da2c90 commit d9700b8

6 files changed

Lines changed: 55 additions & 15 deletions

File tree

src/uucore/build.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,15 @@ fn embed_single_utility_locale(
149149
project_root.join(format!("src/uucore/locales/{locale}.ftl"))
150150
})?;
151151

152+
// Conditionally embed SELinux locales when the selinux feature is enabled
153+
#[cfg(feature = "selinux")]
154+
embed_component_locales(
155+
embedded_file,
156+
locales_to_embed,
157+
"uucore/selinux",
158+
|locale| project_root.join(format!("src/uucore/locales/selinux/{locale}.ftl")),
159+
)?;
160+
152161
Ok(())
153162
}
154163

@@ -199,6 +208,15 @@ fn embed_all_utility_locales(
199208
project_root.join(format!("src/uucore/locales/{locale}.ftl"))
200209
})?;
201210

211+
// Conditionally embed SELinux locales when the selinux feature is enabled
212+
#[cfg(feature = "selinux")]
213+
embed_component_locales(
214+
embedded_file,
215+
locales_to_embed,
216+
"uucore/selinux",
217+
|locale| project_root.join(format!("src/uucore/locales/selinux/{locale}.ftl")),
218+
)?;
219+
202220
embedded_file.flush()?;
203221
Ok(())
204222
}
@@ -230,6 +248,15 @@ fn embed_static_utility_locales(
230248
Path::new(&manifest_dir).join(format!("locales/{locale}.ftl"))
231249
})?;
232250

251+
// Conditionally embed SELinux locales when the selinux feature is enabled
252+
#[cfg(feature = "selinux")]
253+
embed_component_locales(
254+
embedded_file,
255+
locales_to_embed,
256+
"uucore/selinux",
257+
|locale| Path::new(&manifest_dir).join(format!("locales/selinux/{locale}.ftl")),
258+
)?;
259+
233260
// Collect and sort for deterministic builds
234261
let mut entries: Vec<_> = std::fs::read_dir(registry_dir)?
235262
.filter_map(Result::ok)

src/uucore/locales/en-US.ftl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,6 @@ action-creating = creating
3939
action-reading = reading
4040
action-writing = writing
4141
42-
# SELinux error messages
43-
selinux-error-not-enabled = SELinux is not enabled on this system
44-
selinux-error-file-open-failure = failed to open the file: { $error }
45-
selinux-error-context-retrieval-failure = failed to retrieve the security context: { $error }
46-
selinux-error-context-set-failure = failed to set default file creation context to '{ $context }': { $error }
47-
selinux-error-context-conversion-failure = failed to set default file creation context to '{ $context }': { $error }
48-
49-
5042
# Safe traversal error messages
5143
safe-traversal-error-path-contains-null = path contains null byte
5244
safe-traversal-error-open-failed = failed to open { $path }: { $source }

src/uucore/locales/fr-FR.ftl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@ action-creating = création
3939
action-reading = lecture
4040
action-writing = écriture
4141
42-
# Messages d'erreur SELinux
43-
selinux-error-not-enabled = SELinux n'est pas activé sur ce système
44-
selinux-error-file-open-failure = échec de l'ouverture du fichier : { $error }
45-
selinux-error-context-retrieval-failure = échec de la récupération du contexte de sécurité : { $error }
46-
selinux-error-context-set-failure = échec de la définition du contexte de création de fichier par défaut à '{ $context }' : { $error }
47-
selinux-error-context-conversion-failure = échec de la définition du contexte de création de fichier par défaut à '{ $context }' : { $error }
48-
4942
# Messages d'erreur de traversée sécurisée
5043
safe-traversal-error-path-contains-null = le chemin contient un octet null
5144
safe-traversal-error-open-failed = échec de l'ouverture de { $path } : { $source }
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SELinux error messages
2+
# These strings are only loaded when the selinux feature is enabled
3+
4+
selinux-error-not-enabled = SELinux is not enabled on this system
5+
selinux-error-file-open-failure = failed to open the file: { $error }
6+
selinux-error-context-retrieval-failure = failed to retrieve the security context: { $error }
7+
selinux-error-context-set-failure = failed to set default file creation context to '{ $context }': { $error }
8+
selinux-error-context-conversion-failure = failed to set default file creation context to '{ $context }': { $error }
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Messages d'erreur SELinux
2+
# Ces chaînes ne sont chargées que lorsque la fonctionnalité selinux est activée
3+
4+
selinux-error-not-enabled = SELinux n'est pas activé sur ce système
5+
selinux-error-file-open-failure = échec de l'ouverture du fichier : { $error }
6+
selinux-error-context-retrieval-failure = échec de la récupération du contexte de sécurité : { $error }
7+
selinux-error-context-set-failure = échec de la définition du contexte de création de fichier par défaut à '{ $context }' : { $error }
8+
selinux-error-context-conversion-failure = échec de la définition du contexte de création de fichier par défaut à '{ $context }' : { $error }

src/uucore/src/lib/mods/locale.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ fn create_bundle(
153153

154154
// Load common strings from uucore locales directory
155155
try_add_resource_from(find_uucore_locales_dir(locales_dir));
156+
157+
// Conditionally load SELinux locales when the selinux feature is enabled
158+
#[cfg(feature = "selinux")]
159+
try_add_resource_from(find_uucore_locales_dir(locales_dir).map(|p| p.join("selinux")));
160+
156161
// Then, try to load utility-specific strings from the utility's locale directory
157162
try_add_resource_from(get_locales_dir(util_name).ok());
158163

@@ -245,6 +250,13 @@ fn create_english_bundle_from_embedded(
245250
bundle.add_resource_overriding(uucore_resource);
246251
}
247252

253+
// Conditionally load SELinux embedded locales when the selinux feature is enabled
254+
#[cfg(feature = "selinux")]
255+
if let Some(selinux_content) = get_embedded_locale("uucore/selinux/en-US.ftl") {
256+
let selinux_resource = parse_fluent_resource(selinux_content)?;
257+
bundle.add_resource_overriding(selinux_resource);
258+
}
259+
248260
// Then, try to load utility-specific strings
249261
let locale_key = format!("{util_name}/en-US.ftl");
250262
if let Some(ftl_content) = get_embedded_locale(&locale_key) {

0 commit comments

Comments
 (0)