1

so I know this is a not a good question for the StackOverflow format. but I am at a bit of a loss, feel free to recommend a different place to put this where it may get some eyeballs

I am very familliar with the xgettext stuff for localizing your python program. currently we are saving user preferences as strings (eg: user_prefs = {'temperature':u'\u00b0C Fahrenheit', 'volumetric':'Cubic inches', ...} )

this works fine, and when operating in foreign languages we attempt(mostly successfully) to reverse the string localization back to english before saving it. so that the saved string is always the english version, and then we localize them when we start the program.

however it leads to problems later if we change 'Cubic inches' to u'in\u00b3' or even a small change like 'Cubic inches' to 'Cubic Inches'. we have somewhat compensated for this by always doing comparisons in lower case, but it feels hackish to me, and it seems like there must be a better way to do it such as saving an id (be it an index into an array or even just some unique identifier). but wondering about others experiences here with regards to future proofing user preferences so that they will always be recognized.

I suspect this will get closed (asking for subjective answers) but maybe I can get some good insight before it does

4

2 回答 2

1

听起来您正在尝试使用文本的英文表示作为消息的唯一 ID,但是当您更改英文表示时,它不再与您之前存储的首选项文件中的 ID 匹配。解决方案是为每条消息使用唯一且永久的 ID。此 ID 可能是英文可读的,但您必须承诺永不更改它。对此 ID 使用简单且标准化的命名约定可能会有所帮助,不要使用 unicode 或大写字符。例如,一个消息 ID 可能是“立方英寸”。另一个可能是“华氏度”

然后,您应该定义国际化文本,以便以各种语言(包括英语)显示此消息。因此,如果您想在英语系统上显示“立方英寸”消息,您将查找此 ID 的英语等效项并获得“立方英寸”、“立方英寸”、u'in\u00b3 或任何您喜欢的内容。然后您的应用程序可以显示该文本。但是您将始终将永久消息 ID(“立方英寸”)存储在首选项文件中。这使您可以灵活地更改向用户显示的消息的英语表示,而不会使先前存储的首选项文件中的 ID 无效。

于 2014-09-17T21:59:13.180 回答
0

我没有得到你的实际问题,你在哪里存储。但希望“base64 utf 编码解码”可以解决您的问题。

于 2013-05-18T10:49:56.323 回答