4141//! the user's preferred language during a session, and even when it does the
4242//! cost of being one session behind is zero (relaunch picks up the change).
4343
44+ #[ cfg( target_os = "macos" ) ]
4445use std:: collections:: HashMap ;
4546use std:: sync:: LazyLock ;
4647
@@ -121,6 +122,7 @@ pub fn expand(input: &str) -> String {
121122
122123/// One (bundle resource, key) tuple per field. Order doesn't matter; we just
123124/// look up each independently and merge the misses with the English defaults.
125+ #[ cfg( target_os = "macos" ) ]
124126struct StringSource {
125127 /// Absolute path to a `.loctable` (binary plist) inside a system bundle.
126128 loctable : & ' static str ,
@@ -135,6 +137,7 @@ struct StringSource {
135137/// labels). The `Appearance.appex/InfoPlist.loctable` key `CFBundleDisplayName`
136138/// is the bundle's own display name, which is what System Settings renders as
137139/// the pane title.
140+ #[ cfg( target_os = "macos" ) ]
138141struct StringCatalog {
139142 system_settings : StringSource ,
140143 privacy_and_security : StringSource ,
@@ -144,6 +147,7 @@ struct StringCatalog {
144147 appearance : StringSource ,
145148}
146149
150+ #[ cfg( target_os = "macos" ) ]
147151const CATALOG : StringCatalog = StringCatalog {
148152 system_settings : StringSource {
149153 loctable : "/System/Applications/System Settings.app/Contents/Resources/Localizable.loctable" ,
@@ -212,12 +216,12 @@ fn build_snapshot() -> LocalizedSystemStrings {
212216 // Stubs/Linux: the labels never reach the UI (the surfaces that use them
213217 // are macOS-only modals), but the snapshot exists so the IPC command
214218 // returns something sensible if a Linux harness calls it.
215- let _ = & CATALOG ;
216219 LocalizedSystemStrings :: english_defaults ( )
217220}
218221
219222/// Parsed loctable: outer key is the language code (`en`, `hu`, `en_GB`,
220223/// `pt-PT`, ...), inner map is `string_key → localized_value`.
224+ #[ cfg( target_os = "macos" ) ]
221225type LoctableData = HashMap < String , HashMap < String , String > > ;
222226
223227#[ cfg( target_os = "macos" ) ]
@@ -244,14 +248,10 @@ fn parse_loctable(path: &str) -> Option<LoctableData> {
244248 Some ( out)
245249}
246250
247- #[ cfg( not( target_os = "macos" ) ) ]
248- fn parse_loctable ( _path : & str ) -> Option < LoctableData > {
249- None
250- }
251-
252251/// Picks the first language in `langs` whose loctable entry for `key` exists.
253252/// Falls back to `en` last, so a missing target language still produces the
254253/// canonical English string before bailing to `None`.
254+ #[ cfg( target_os = "macos" ) ]
255255fn lookup_in_table ( table : & LoctableData , langs : & [ String ] , key : & str ) -> Option < String > {
256256 for candidate in candidate_lang_codes ( langs) {
257257 if let Some ( inner) = table. get ( & candidate)
@@ -268,6 +268,7 @@ fn lookup_in_table(table: &LoctableData, langs: &[String], key: &str) -> Option<
268268/// candidates: the original, an `_`-normalized form (`en-GB` → `en_GB`), and
269269/// the base language (`en-GB` → `en`). Duplicates are dropped while preserving
270270/// order. `en` is appended at the end as a universal fallback.
271+ #[ cfg( target_os = "macos" ) ]
271272fn candidate_lang_codes ( preferred : & [ String ] ) -> Vec < String > {
272273 let mut out: Vec < String > = Vec :: with_capacity ( preferred. len ( ) * 3 + 1 ) ;
273274 let mut seen: std:: collections:: HashSet < String > = std:: collections:: HashSet :: new ( ) ;
@@ -301,15 +302,11 @@ fn apple_languages() -> Vec<String> {
301302 array. iter ( ) . map ( |s| s. to_string ( ) ) . collect ( )
302303}
303304
304- #[ cfg( not( target_os = "macos" ) ) ]
305- fn apple_languages ( ) -> Vec < String > {
306- vec ! [ "en" . to_string( ) ]
307- }
308-
309305#[ cfg( test) ]
310306mod tests {
311307 use super :: * ;
312308
309+ #[ cfg( target_os = "macos" ) ]
313310 #[ test]
314311 fn candidate_codes_handle_bcp47_to_underscore_and_base ( ) {
315312 let out = candidate_lang_codes ( & [ "en-GB" . to_string ( ) , "hu-HU" . to_string ( ) ] ) ;
@@ -325,12 +322,14 @@ mod tests {
325322 assert ! ( out. contains( & "en" . to_string( ) ) ) ;
326323 }
327324
325+ #[ cfg( target_os = "macos" ) ]
328326 #[ test]
329327 fn candidate_codes_dedupe_when_base_matches_original ( ) {
330328 let out = candidate_lang_codes ( & [ "en" . to_string ( ) ] ) ;
331329 assert_eq ! ( out, vec![ "en" . to_string( ) ] ) ;
332330 }
333331
332+ #[ cfg( target_os = "macos" ) ]
334333 #[ test]
335334 fn candidate_codes_always_include_english_fallback ( ) {
336335 let out = candidate_lang_codes ( & [ "fi" . to_string ( ) ] ) ;
@@ -347,6 +346,7 @@ mod tests {
347346 assert ! ( out. contains( "{unknown_token}" ) ) ;
348347 }
349348
349+ #[ cfg( target_os = "macos" ) ]
350350 #[ test]
351351 fn lookup_in_table_walks_candidate_languages_in_order ( ) {
352352 let mut table: LoctableData = HashMap :: new ( ) ;
0 commit comments