android - Delphi TFormatSettings 的输出不正确,在 Windows 中可以,但在 Android 中不行

标签 android delphi locale delphi-xe7

我正在编写一个多平台单元,其中包括使用 Delphi 的 TFormatSettings。我希望创建一个全局 TFormatSettings 来让我访问我的家(英国)位置信息,而不管我的代码将被使用的实际语言环境如何(例如,我需要英国小数点分隔符和列表分隔符,它们因国家/地区而异)。我只是想读取这些值,而不是更改它们或修改实际的机器语言环境。为了测试我是否可以通过这种方式获取信息,我尝试了下面的代码。该代码在 32/64 Windows 中运行良好(返回美元符号后跟英镑符号),但在我 2 岁的 Nexus 7 上运行 Android 时返回两个输出的美元符号。

它是使用 XE7 和多设备应用程序创建的。

procedure TForm2.Button1Click(Sender: TObject);
var
  FS : TFormatSettings;
begin
  FS := TFormatSettings.Create( 'en-US' );
  ShowMessageFmt( FS.CurrencyString );

  FS := TFormatSettings.Create( 'en-UK' );
  ShowMessage( FS.CurrencyString );
end;

我尝试了各种其他位置字符串但没有成功。我已经深入到 SysUtils 中的“LIBICU”代码,但我正在扩展调试器和我的知识!谁能评论我可能做错了什么?感谢您的帮助。

稍后编辑 已解决:要在 Android 中使用英国,您需要传递“en_GB”而不是“en-UK”。 this Java link 上有很多有用的信息Uwe Raabe 也展示了这一点。

最佳答案

虽然请求的语言环境可能可用,但不能保证:

(来自http://developer.android.com/reference/java/util/Locale.html)

Note that locale data is not necessarily available for any of the locales pre-defined as constants in this class except for en_US, which is the only locale Java guarantees is always available.

It is also a mistake to assume that all devices have the same locales available. A device sold in the US will almost certainly support en_US and es_US, but not necessarily any locales with the same language but different countries (such as en_GB or es_ES), nor any locales for other languages (such as de_DE). The opposite may well be true for a device sold in Europe.

当语言环境不可用时,我希望至少有一条错误消息,但在这种情况下,RTL 似乎会回退到 en_US(请参阅 TFormatSettings.AdjustLocaleName)。

关于android - Delphi TFormatSettings 的输出不正确,在 Windows 中可以,但在 Android 中不行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25922256/

相关文章:

java - 分词和模式匹配在中文中是如何工作的?

android - 获取 JSONArray 时 Retrofit2 + Gson IllegalStateException

windows - 在我的应用程序播放声音时将其他应用程序静音

arrays - 如何创建具有二维或多维数组参数的过程?

Delphi 7 更新连接表

android - Locale.getDefault() 在某些 Android 设备上已过时

gwt - 以格林威治标准时间获取客户时区

android - Meteor 应用程序在 Android 上的 chrome 浏览器中打开 URL

android - 如何使用 Google Analytics 跟踪我的 Android 应用程序中的搜索查询?

android - Android 4.x 中的 TextView 字体