Function for getting localized path?

不羁岁月 提交于 2019-12-18 06:13:16

问题


Windows 7 (and probably Windows Vista) display localized folder names using the LocalizedResourceName entry in the desktop.ini file. For my Documents folder, this looks like

[.ShellClassInfo]
LocalizedResourceName=@%SystemRoot%\system32\shell32.dll,-21770
IconResource=%SystemRoot%\system32\imageres.dll,-112
IconFile=%SystemRoot%\system32\shell32.dll
IconIndex=-235

(see this question)

This way the explorer displays the path "C:\Users\Username\Documents" as "C:\Benutzer\Username\Dokumente" on a german Windows.

I wonder, if there's any build-in shell function to automatically get this localized name or, even better, transform a whole path into its localized form (best would be anything in .NET)?

This is even more interesting as the LocalizedResourceName entry is only documented for Windows CE (see here).

Thanks

Martin


回答1:


SHGetLocalizedName(). There is a PInvoke sample on Michael Kaplan's blog.




回答2:


I'm pretty sure there isn't a function to transform a path to its localized form because when you see the bigger picture it doesn't make sense. If you have a roaming profile there might not even be a "Users" or "Benutzer" folder because it would all be wherever the server admin put it.

It also begs the question of how you call this function. For the sake of argument we'll just assume that you call it with the US English defaults. If you say "give me the German localized version of c:\Users\Bob", Vista and Windows 7 will be fine with this but XP doesn't know about the "Users" folder. So that would break without a backwards patch that you can't guarantee would be installed.

Generally Microsoft recommends not even worrying about the left half of a path. Instead you're just supposed to use Environment.GetFolderPath() and pass it one of the SpecialFolder enumerations. Anything after the special folder part is yours to define and create but that's it. Your code should say, "relative to the desktop create a folder called Bob". Whatever that resolves to should never be stored because its possible for that path to change some day,



来源:https://stackoverflow.com/questions/4692425/function-for-getting-localized-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!