【问题标题】:NET CF Localization with Orientation Aware具有方向感知的 NET CF 本地化
【发布时间】:2010-10-21 15:07:00
【问题描述】:

是否有人成功本地化了使用方向感知控件以支持多种分辨率的移动应用程序。 CultureInfo 需要在运行时设置,而不是从系统中读取。不确定这是否受支持。请帮忙。

普拉门

【问题讨论】:

    标签: .net compact-framework localization


    【解决方案1】:

    我从未使用过您提到的控件,也不知道您必须在运行时为所述控件设置 CultureInfo 的原因。因此,我的回复是基于您的问题如何在运行时设置 CultureInfo。如果这不是您想要的,请忽略我的回复。

    如果我们正在编写桌面应用程序,可以使用以下方法更改 CultureInfo:

    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US")
    'en-US = American English
    

    很遗憾,这在 CF.NET 中是不可能的。

    事实上,据我所知,没有官方或支持的方式可以在运行期间在 CF.NET 中更改设备的 CultureInfo(和区域设置)。也许可以更改注册表中的区域设置,但这意味着必须重新启动设备。

    但是,在我的代码库中,我有一个 code-sn-p,这是我前段时间发现的,我只在一个运行良好的模拟器中进行了测试。 这被认为是“黑客”,可能存在风险,但在模拟器中进行测试时,我从未遇到任何问题。这是在 VB.Net 中:

    'I declare the following statement
    
    Dim myCIintl As New Globalization.CultureInfo("en-US") 'where en-US is for Ame-English
    
    'Then I call the following sub
    
    SetDefaultLocale(myCIintl)
    
    'Here is the code of the sub
    
    Public Shared Sub SetDefaultLocale(ByVal locale As System.Globalization.CultureInfo)
            If Nothing Is locale Then
                Throw New ArgumentNullException("locale")
            End If
    
            Dim fi As System.Reflection.FieldInfo = GetType(System.Globalization.CultureInfo).GetField _
            ("m_userDefaultCulture", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Static)
            If Nothing Is fi Then
                Throw New NotSupportedException("Setting locale is not supported in this version of the framework.")
            End If
            fi.SetValue(Nothing, locale)
    End Sub
    

    注意:请注意,如果私有变量 m_userDefaultCulture 将在未来版本中更改其名称,则上述代码可能会中断。此外,该变量的名称在 Windows Mobile 的本地化版本中可能有另一个名称 - 也许在西班牙语版本中它被称为其他名称。我不知道,所以我想你必须自己尝试一下。

    除了上面提到的注意事项之外,只要设备上存在您希望使用的区域设置,上述代码应该可以工作(我的手指交叉)。要查看设备支持哪些区域设置,您可以使用 Ctacke 展示的优秀代码 here

    祝你好运!

    【讨论】:

      猜你喜欢
      • 2019-04-12
      • 2013-01-05
      • 2014-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-26
      • 1970-01-01
      相关资源
      最近更新 更多