You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

未本地化的Xamarin.iOS为何让NSDateFormatter遵循系统区域设置?

Xamarin.iOS 未本地化应用的区域设置特殊行为解析

场景说明

当iOS系统设置(设置→通用→语言与地区)设为法语(加拿大地区),而应用开发环境为英文(us-EN)时,未做法语本地化的Xamarin.iOS(C#)应用会自动遵循系统区域设置,这与原生Swift应用的常规表现截然不同。


Xamarin.iOS 测试示例

C# 测试代码

Console.WriteLine($"App Locale {NSLocale.CurrentLocale.Identifier}");
Console.WriteLine($"System Locale {NSLocale.PreferredLanguages[0]}");

var formatter = new NSDateFormatter();
formatter.DateStyle = NSDateFormatterStyle.Full;
formatter.TimeStyle = NSDateFormatterStyle.Short;
var stringDate = formatter.ToString(NSDate.Now);
Console.WriteLine(stringDate);

输出结果

App Locale fr_CA <<<---
System Locale fr-CA
samedi 15 octobre 2022 à 22:52

这种行为让未本地化的应用无需额外适配,就能直接获取符合系统设置的本地化日期时间,同时支持24小时制的自动切换。


Swift 原生应用对比

Swift 测试代码

print("App Locale \(Locale.current.identifier)")
print("System Locale \(Locale.preferredLanguages[0])")

let formatter = DateFormatter()
formatter.dateStyle = .full
formatter.timeStyle = .short
let stringDate = formatter.string(from: Date())
NSLog(stringDate)

输出结果

App Locale en_CA <<<---
System Locale fr-CA
Saturday, October 15, 2022 at 10:55 PM

未本地化的Swift应用会默认使用en_CA(英语+加拿大地区)作为应用区域设置,符合iOS平台的常规预期。


核心疑问

Xamarin.iOS是通过什么机制,让未本地化的应用强制跟随系统区域设置的?


内容的提问来源于stack exchange,提问作者t9mike

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 03:15:36