I’m currently working on a WPF application and using the TextBlock.IsHyphenationEnabled
property to handle text hyphenation. I understand that hyphenation behavior can be culture-specific, and I’m trying to ensure proper functionality across different languages.
Could anyone provide a list of cultures that are officially supported for hyphenation when using the TextBlock.IsHyphenationEnabled
property? Specifically, I’m interested in knowing if languages like Swedish (sv-SE), German (de-DE), and others are fully supported.
I see some code related to it but not sure how culture support is done:
Class: NaturalLanguageHyphenator
public override bool IsCultureSupported(CultureInfo culture)
{
// Accept all cultures for the time being. Ideally, NL6 should provide a way for the client to test supported culture.
return true;
}
Additionally, if any specific settings or configurations are required on the client machine, such as installing language packs in Windows
Code and debugging values for TextBlock and Culture info (sv-SE not working here)
<TextBlock IsHyphenationEnabled="True"
Text="{Binding Name}" Language="sv-SE"
TextWrapping="Wrap"/>
System.Globalization.CultureInfo.CurrentCulture - en-IN System.Globalization.CultureInfo.CurrentUICulture - sv
Any documentation or experiences you can share would be greatly appreciated!
Thanks in advance for your help.
1
This is not an answer, but it may help in the investigation.
As you may suspect, Hyphenation is done with the use of native dll. Most probably it is C:WindowsSystem32NaturalLanguage6.dll
at very end.
There is a PresentationNative_xxxxx.dll
in the middle, but it doesn’t matter right now. NL6 team doesn’t provide a way for the client to test supported culture, as we can read from the comment.
NaturalLanguage6.dll
exports 4 functions: DllCanUnloadNow
, DllGetClassObject
, DllRegisterServer
and DllUnregisterServer
so it’s a COM library.
I’ve found 4 CLSIDs related to this dll: {0E1EEFB2-E336-481C-B178-36261EC5A843}, {333E6924-4353-4934-A7BE-5FB5BDDDB2D6}, {89EA5B5A-D01C-4560-A874-9FC92AFB0EFA} and {D385FDAD-D394-4812-9CEC-C6575C0B2B38}, but I can’t find much more. I tried to use OleView.exe
to inspect NaturalLanguage6.dll
, but it failed.
To make thing worse, there is no guarantee that PresentationNative_xxxxx.dll
uses NaturalLanguage6.dll
, especially on platforms different than Windows.
Anyway it seems that:
- .NET team doesn’t know which cultures are supported,
- functionality is buried deep in Windows system dlls,
- supported cultures may change with Windows updates.
Since it’s pointless to call PresentationNative
‘s methods (there’s none that would help), the next likely step will be to decompile the dll to see what’s inside.
1
IsHyphenationEnabled
works with any culture language that:
- Is installed (e.g. via Language Pack)
- Has a valid
LCID
(i.e. not 4096)
To determine which languages are installed, you can use the GetInstalledInputLanguages()
method in this answer.
Then, to determine which cultures allow for hyphenation, we can use this method:
private static ICollection<CultureInfo> GetInstalledCultures()
{
var languages = GetInstalledInputLanguages()
.Select(c => c.TwoLetterISOLanguageName)
.ToHashSet();
var cultures = CultureInfo.GetCultures(CultureTypes.AllCultures)
.Where(c => c.LCID != 4096)
.Where(c => languages.Contains(c.TwoLetterISOLanguageName))
.ToList();
return cultures;
}
On my system, I have en-US
and en-GB
installed which yield the following hyphenation-enabled cultures:
en, en-029, en-AU, en-BZ, en-CA, en-GB, en-HK, en-ID, en-IE, en-IN,
en-JM, en-MY, en-NZ, en-PH, en-SG, en-TT, en-US, en-ZA, en-ZW
1