FUILocale
public class FUILocale : NSObject
FUILocale is a global singleton used to override the locale applied by the SAPFiori framework when presenting its own default (framework‑provided) messages. If you do not set a custom locale (locale == nil), the framework falls back to the current device locale.
Purpose
Enables in‑app language switching or enforcing a specific language for framework strings independently of the app’s device locale setting.
Scope
Affects only SAPFiori framework messages that consult this override. Your application’s own localized content remains governed by standard iOS localization APIs unless you explicitly use FUILocale.shared.locale elsewhere.
Resolution Algorithm (executed when locale is set)
- Extract
languageCodefrom the providedLocale. - If language is one of:
de,en,es,fr,it,ptand a region subtag exists (e.g.en_CA), construct a region variant:en-CA. - If language is
zh(Chinese):- If a script subtag exists (
Hans,Hant, etc.), constructzh-<Script>(e.g.zh-Hant). - If no script subtag provided, default to
zh-Hans(Simplified).
- If a script subtag exists (
- Attempt to load a localization bundle for the region/script variant first (
<variant>.lproj). - If not found, attempt the base language (or language+script for Chinese) bundle (
<language>.lproj,zh-Hant.lproj). - If neither is found, internal
bundlebecomesniland the override has no effect (framework reverts to device locale behavior for its strings).
Supported Special Handling
- Region variants:
de,en,es,fr,it,pt - Chinese script variants:
zh-Hans,zh-Hant(defaults toHansif unspecified)
Examples
// Force French (Canada)
FUILocale.shared.locale = Locale(identifier: "fr_CA")
// Traditional Chinese
FUILocale.shared.locale = Locale(identifier: "zh-Hant")
// Portuguese (Brazil)
FUILocale.shared.locale = Locale(identifier: "pt_BR")
// Revert override (use device locale)
FUILocale.shared.locale = nil
Best Practices
- Set early (AppDelegate / SceneDelegate) so initial framework UI uses the override.
- Persist user preference (e.g. in
UserDefaults) and reapply on launch. - After changing, refresh or recreate visible Fiori views to force re-resolution of strings.
- Avoid frequent toggling; prefer a single change per session.
Thread Safety
Not synchronized. Perform mutations on the main thread to avoid race conditions if changed during active UI updates.
When to Use
- In-app language selection independent from device settings.
- Enforcing a single language for framework messages while app content varies.
When NOT to Use
- General app localization (use standard iOS localization tools).
- Scene-specific differing languages (singleton is global).
Edge Cases & Notes
- Unsupported languages simply result in
bundle == nil(graceful fallback; no crash). - Malformed locale identifiers do not crash; resolution silently fails.
- Chinese without script defaults to Simplified (
zh-Hans).
FAQ
- Q: Does changing
localelive-update existing framework UI? A: No. You must refresh/redraw affected views. A: No. You must refresh/redraw affected views. - Q: Does it affect date/number formatting globally? A: Only where Fiori internal logic uses this override; your own formatting code is unaffected unless you query it.
- Q: Multiple locales per scene? A: Not supported—singleton is global.
Summary
FUILocale offers a controlled, lightweight mechanism to tailor SAPFiori framework language handling with clear fallback behavior.
-
The shared singleton
FUILocaleinstance.Declaration
Swift
public static let shared: FUILocale -
Override locale for SAPFiori framework default messages.
- Default:
nil(device locale used). - Resolution: Region/script variant -> base language/script -> none.
- Region variants honored for:
de,en,es,fr,it,pt. - Chinese script: adds
Hansor uses provided script (e.g.Hant).
Setting this property triggers bundle resolution immediately.
Example:
FUILocale.shared.locale = Locale(identifier: "fr_CA") FUILocale.shared.locale = Locale(identifier: "zh-Hant") FUILocale.shared.locale = nilEdge Cases:
- Unsupported language =>
bundle == nil(silent fallback). - Malformed identifier => no crash, resolution fails.
Declaration
Swift
public var locale: Locale? { get set } - Default: