Is there a repository for localized common text in

2019-01-20 14:26发布

问题:

I'm globalizing a Windows form application.

Is there a way to access common text in the current language for Windows?

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.

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?

回答1:

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.

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.

Note, however, that Windows will automatically localize the captions for buttons on a message box (MessageBox). You don't have to lift a finger.

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.



回答2:

This seems to have some information regarding that:

The USER32.dll is indeed the repository for localized string in Windows.

However, it does not not contains multiple string tables, only one.

I've access to some other localized Windows versions (pt-BR, es-ES, among others) and in every one of them the following positions are fixed from Window XP through Windows 7:

800 - OK 801 - Cancel 802 - &Abort ...

I'd still treat this as an implementation detail and nothing to rely on. Read Raymond Chen's blog for various horror stories of developers that took Windows-internal things for granted and eternal.

Also why not just have your own strings? You can easily put “OK” on the button yourself instead of grabbing it from the OS (and then localize it yourself if your application is intended to be localized). As a user I find it mildly confusing to have parts of an interface in another language than the rest (which would then invariably happen if your program has no localization, say, in German and is used on a German Windows machine – this would leave the interface in English with only the buttons in German).