feat(v3): add cross-platform SystemLocale() API (BCP-47 language tag) - #5894
feat(v3): add cross-platform SystemLocale() API (BCP-47 language tag)#5894mortenolsrud wants to merge 1 commit into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (13)
🚧 Files skipped from review as they are similar to previous changes (13)
WalkthroughThe application package now exposes ChangesSystem Locale Support
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant MobileManager
participant AndroidWailsBridge
participant IOSNativeLocale
MobileManager->>AndroidWailsBridge: getLocale()
AndroidWailsBridge-->>MobileManager: BCP-47 locale
MobileManager->>IOSNativeLocale: ios_system_locale()
IOSNativeLocale-->>MobileManager: BCP-47 locale
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@v3/pkg/application/locale_android.go`:
- Around line 8-10: The Android locale bridge methods must return the documented
"en" fallback when the bridge errors or returns an empty string. Update
SystemLocale in v3/pkg/application/locale_android.go (lines 8-10) and the
corresponding method in v3/pkg/application/mobile_features_android.go (lines
145-147) to retain the bridge error and return "en" when err is non-nil or s is
empty; otherwise preserve the returned locale.
In `@v3/pkg/application/locale_ios.go`:
- Around line 5-8: Update SystemLocale in locale_ios.go by adding a cgo preamble
declaring ios_system_locale(void) and importing the C pseudo-package before the
package declaration, so the existing C.ios_system_locale() call resolves during
the iOS build.
In `@v3/pkg/application/locale_linux.go`:
- Line 1: Update the build constraint for the Linux provider in locale_linux.go
to require !server in addition to linux && !android, preventing it from
compiling alongside the server-specific SystemLocale implementation.
In `@v3/pkg/application/locale_server.go`:
- Around line 13-20: Update the locale normalization logic in the shown function
to remove any suffix beginning with “@” before replacing underscores and
returning the tag, matching parsePosixLocale’s handling. Preserve the existing
dot truncation, fallback to “en” for empty/C/POSIX values, and normalized locale
return behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 6ea299d1-88b4-4765-afd0-c461d71ddb22
📒 Files selected for processing (12)
v3/internal/commands/build_assets/android/app/src/main/java/com/wails/app/WailsBridge.javav3/pkg/application/locale_android.gov3/pkg/application/locale_darwin.gov3/pkg/application/locale_ios.gov3/pkg/application/locale_linux.gov3/pkg/application/locale_server.gov3/pkg/application/locale_windows.gov3/pkg/application/mobile.gov3/pkg/application/mobile_features_android.gov3/pkg/application/mobile_features_ios.gov3/pkg/application/mobile_features_ios.mv3/pkg/application/mobile_stub.go
4523141 to
8789385
Compare
|
Addressed in the force-push:
2-4. iOS symbol / Linux build tag / Server modifier — These were already fixed in the previous force-push (before CodeRabbit's review ran). The review was against the pre-fix commit. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@v3/pkg/application/locale_darwin.go`:
- Around line 18-22: Update the legacy locale fallback in the locale retrieval
implementation to preserve script and variant subtags, rather than constructing
the tag solely from languageCode and countryCode. Use a canonical or explicit
locale identifier API compatible with macOS versions below 13, ensuring values
such as zh-Hant_TW retain all available components.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 00a95efa-b787-4c16-9f3d-2f7641db83ac
📒 Files selected for processing (13)
v3/internal/commands/build_assets/android/app/src/main/java/com/wails/app/WailsBridge.javav3/pkg/application/locale_android.gov3/pkg/application/locale_darwin.gov3/pkg/application/locale_ios.gov3/pkg/application/locale_linux.gov3/pkg/application/locale_server.gov3/pkg/application/locale_windows.gov3/pkg/application/mobile.gov3/pkg/application/mobile_features_android.gov3/pkg/application/mobile_features_ios.gov3/pkg/application/mobile_features_ios.hv3/pkg/application/mobile_features_ios.mv3/pkg/application/mobile_stub.go
🚧 Files skipped from review as they are similar to previous changes (9)
- v3/pkg/application/mobile_features_ios.go
- v3/pkg/application/mobile_features_android.go
- v3/pkg/application/mobile_stub.go
- v3/pkg/application/locale_android.go
- v3/pkg/application/locale_windows.go
- v3/pkg/application/locale_ios.go
- v3/pkg/application/mobile.go
- v3/pkg/application/locale_linux.go
- v3/internal/commands/build_assets/android/app/src/main/java/com/wails/app/WailsBridge.java
8789385 to
bcc9d55
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@v3/pkg/application/mobile_features_ios.m`:
- Around line 717-718: Remove the duplicate file-scope `return mfDup(tag);`
statement and its accompanying closing brace immediately after
`ios_system_locale`; retain the valid return and function closure already
present in that function.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: fb5ae7f7-eeda-4b73-97c0-3d13736d25a3
📒 Files selected for processing (13)
v3/internal/commands/build_assets/android/app/src/main/java/com/wails/app/WailsBridge.javav3/pkg/application/locale_android.gov3/pkg/application/locale_darwin.gov3/pkg/application/locale_ios.gov3/pkg/application/locale_linux.gov3/pkg/application/locale_server.gov3/pkg/application/locale_windows.gov3/pkg/application/mobile.gov3/pkg/application/mobile_features_android.gov3/pkg/application/mobile_features_ios.gov3/pkg/application/mobile_features_ios.hv3/pkg/application/mobile_features_ios.mv3/pkg/application/mobile_stub.go
🚧 Files skipped from review as they are similar to previous changes (12)
- v3/pkg/application/mobile_features_ios.go
- v3/pkg/application/locale_ios.go
- v3/pkg/application/locale_windows.go
- v3/pkg/application/mobile_features_ios.h
- v3/internal/commands/build_assets/android/app/src/main/java/com/wails/app/WailsBridge.java
- v3/pkg/application/locale_server.go
- v3/pkg/application/mobile_stub.go
- v3/pkg/application/locale_android.go
- v3/pkg/application/locale_linux.go
- v3/pkg/application/mobile.go
- v3/pkg/application/mobile_features_android.go
- v3/pkg/application/locale_darwin.go
Add application.SystemLocale() returning the device/system locale as a BCP-47 language tag (e.g. "nb-NO", "en-US") on all platforms: Android: Locale.getDefault().toLanguageTag() via WailsBridge iOS: NSLocale.currentLocale.localeIdentifier (underscore→hyphen) macOS: NSLocale.currentLocale (Foundation framework) Windows: GetUserDefaultLocaleName (kernel32.dll) Linux: $LC_ALL / $LC_MESSAGES / $LANG parsed to BCP-47 Also adds SystemLocale() to the MobileManager interface, so it is accessible via application.Mobile.SystemLocale() on mobile platforms (delegates to the platform-specific implementation). Usage: locale := application.SystemLocale() // works everywhere // or on mobile: locale := application.Mobile.SystemLocale()
bcc9d55 to
0218d2f
Compare
Description
There is no way to get the system/device locale from Go code in a Wails app. On Android, the
LANG/LC_ALLenv vars are not set in the app sandbox; on iOS, the locale is only accessible via Foundation; on desktop platforms, the approach differs per OS.This adds a unified
application.SystemLocale()function that returns the BCP-47 language tag (e.g. "nb-NO", "en-US") on all platforms:Also adds
SystemLocale()to theMobileManagerinterface for mobile access viaapplication.Mobile.SystemLocale().Per-platform implementations:
Locale.getDefault().toLanguageTag()getLocale()method)NSLocale.currentLocale.localeIdentifierios_system_locale())NSLocale.currentLocaleGetUserDefaultLocaleName()$LC_ALL/$LC_MESSAGES/$LANGAll implementations normalize to BCP-47 (hyphen-separated) and fall back to
"en"if detection fails.Type of change
How Has This Been Tested?
Linux (GTK3) build — compiles,
SystemLocale()returns the host's$LANGvalue.Android cross-compile (
android/arm64via NDK) — compiles.Windows cross-compile (
GOOS=windows CGO_ENABLED=0) — compiles.Host-side command tests — pass.
iOS:
ios_system_locale()follows the samemfDup()pattern asios_network_json()etc.Windows
macOS
Linux
Test Configuration
Checklist:
Note: The Linux implementation can be unit-tested on the host (reads env vars). A quick follow-up could add a test for
parsePosixLocale. The mobile/macOS/Windows implementations require their respective platforms.Summary by CodeRabbit
en-US.