問題描述
我正在全球化一個 Windows 表單應用程序.
I'm globalizing a Windows form application.
有沒有辦法以 Windows 的當前語言訪問常用文本?
Is there a way to access common text in the current language for Windows?
例如對于OK、Cancel和Accept按鈕的標簽;如果我正在構建一個帶有 OK 按鈕的表單,我想使用 Windows 在其他地方為 OK 按鈕使用的相同翻譯.
For example, for the labels of OK, Cancel and Accept buttons; if I'm building a form that has an OK button I would like to use the same translation that Windows uses everywhere else for OK buttons.
我知道我可以自己存儲翻譯,但 Windows 必須將它們存儲在某個地方,它們是否允許開發人員訪問它們?
I know I can store the translation for them myself, but Windows has to have them stored somewhere, do they give developers access to them?
推薦答案
是的,理論上你可以從 Windows 的內部系統文件中提取本地化字符串.但不要這樣做.可能的缺點遠遠超過了優點.您的應用程序不應依賴于未記錄的實現細節.沒有理由嘗試從 Windows 獲取它.
Yes, theoretically you could extract localized strings from Windows's internal system files. But don't do it. The advantages are far outweighed by the possible disadvantages. Your application shouldn't be reliant on undocumented implementation details. There's no reason to try and get this from Windows.
還值得指出的是,您可以重命名按鈕(以及所有其他控件).這意味著如果您依賴某種字符串匹配算法,那么很容易破壞某些東西.沒有辦法將按鈕標記為某種類型",以便它自動與特定標題關聯,即使您可以,這也不會涵蓋非-瑣碎的用戶界面.此外,正如 Joey 的回答所指出的,對于用戶而言,沒有什么比 部分 本地化的 UI 更糟糕的了.一致性是關鍵,您無法通過這種方式本地化標簽、分組框、菜單、工具提示等.
It's also worth pointing out that you can rename buttons (and every other control). That means it's too easy to break something if you're relying on some kind of string matching algorithm. There's no way to mark a button as being a certain "type" so that it will be automatically associated with a particular caption, and even if you could, this wouldn't cover every button present in a non-trivial UI. Also, as Joey's answer points out, there's nothing worse for the user than a partially localized UI. Consistency is the key, and you can't localize labels, group boxes, menus, tooltips, etc. this way.
但請注意,Windows會自動本地化消息框上按鈕的標題(MessageBox
).您不必抬起一根手指.
Note, however, that Windows will automatically localize the captions for buttons on a message box (MessageBox
). You don't have to lift a finger.
將表單的 Localizable
屬性設置為 True(您必須在設計時這樣做)并為應用程序中的所有控件提供本地化文本有什么問題?Windows 窗體實際上對本地化提供了相當全面的支持;設計器會自動將所有可本地化的元素序列化到表單的 RESX 文件中.請參閱 MSDN:演練:本地化 Windows 窗體.確保留出足夠的空間以允許不同語言中不同長度的表達式.
What's wrong with setting the form's Localizable
property to True (you must do this at design time) and providing localized text for all of the controls in your application? Windows Forms actually has pretty comprehensive support for localization; the designer will automatically serialize all localizable elements to the form's RESX file. See MSDN: Walkthrough: Localizing Windows Forms. Make sure that you leave a sufficient amount of space to allow for the varying lengths of expressions in different languages.
這篇關于WinForms 中是否有本地化常用文本的存儲庫?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!