Reputation: 63
Suppose the PC has English and Spanish languages installed.
How do I get the text strings for a property column heading in both English and Spanish?
For example, how could I get the heading text for either the canonical name "System.ItemNameDisplay"
or the PKEY_FileName
column in both English and Spanish?
Currently, I use PSGetPropertyDescriptionByName()
and IPropertyDescription::GetDisplayName()
to get the column name from the canonical name. It returns the name in the current language. I can't see how to select the language using a LANGID
.
IColumnManager::GetColumnInfo()
could give me the column name, but appears to depend on an IShellView
object which the program doesn't have. Even if I could use it, I can't see how it would support a LANGID
.
I saw a ten year old StackOverflow post, Temporarily change locale settings, implying that temporary changes to the current locale is not the way to go. I suspect this is still true.
I have investigated IPropertStore
, and IPropertyStorage
, and spent hours searching.
Ideally, I'd implement a function that takes a LANGID
and a property, and returns the text value of the property in the given language.
Upvotes: 1
Views: 89
Reputation: 139187
You can just change the thread UI language to the language you need, for example with SetThreadUILanguage function, and use IPropertyDescription::GetDisplayName.
For example this console app sample code:
int main()
{
CoInitialize(nullptr);
IPropertyDescription* desc;
PSGetPropertyDescription(PKEY_FileName, IID_PPV_ARGS(&desc));
LPWSTR name;
SetThreadUILanguage(1033);
desc->GetDisplayName(&name);
wprintf(L"english: %s\n", name);
CoTaskMemFree(name);
SetThreadUILanguage(1036);
desc->GetDisplayName(&name);
wprintf(L"french: %s\n", name);
CoTaskMemFree(name);
desc->Release();
CoUninitialize();
return 0;
}
Will output:
english: Filename
french: Nom de fichier
Upvotes: 2