jazza
Topic Author
Posts: 5
Joined: 26 Sep 2019, 08:32

NOESIS Samples - Localization and language specific fonts

09 Jan 2020, 01:28

Hi all,

I am trying to understand how the NOESIS "Localization" example chooses a font to render a localised string. I can see that 'Main.cpp' lists Japanese and English fonts but I cannot see anything in the code that specifies which font to use based on the current language.

Additionally, if my game has several fonts for a language, is there a way for me to specify which one to use?
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: NOESIS Samples - Localization and language specific fonts

09 Jan 2020, 10:21

Hello,

Our localization sample sets the fonts in the root of MainWindow.xaml:
FontFamily="./#Oxygen, ./#FontopoNIHONGO"
When specifying multiple fonts in a FontFamily, characters are rendered using the first font in the list that contains the corresponding glyph.
In this sample, when writing English/French, all latin characters can be fond inside Oxygen font. When writing Japanese, the characters are found inside FontopoNIHONGO font.

If your game wants to use different fonts for different parts of the UI you can set the FontFamily property as explained in our Text tutorial. Is that what you need?
 
jazza
Topic Author
Posts: 5
Joined: 26 Sep 2019, 08:32

Re: NOESIS Samples - Localization and language specific fonts

10 Jan 2020, 04:10

Thanks for the prompt reply! I noticed the font family on the root window of the XAML after I wrote my post but still wasn't sure how NOESIS decided which one to use. It's alot clearer now so thank you.

While we're on the topic of localisation, I am curious about whether my chosen approach is appropriate. I am currently integrating NOESIS with a proprietary engine that has a Localisation class with a built in dictionary of keywords and matching localised strings. A function on this class takes an input string and returns a localised value based on the user's preferred language.

I figure that the best way to leverage this class via NOESIS is to use a value converter like so -
bool LocalisationConverter::TryConvert(BaseComponent* value, const Type* targetType, BaseComponent* parameter,
	Ptr<BaseComponent>& result)
{
	bool converted = false;
	if (targetType == TypeOf<NsString>())
	{
		// If the bound value is null, convert the parameter instead
		BaseComponent* valueToConvert = value == NULL ? parameter : value;
		if (Boxing::CanUnbox<NsString>(valueToConvert))
		{
			NsString sourceString = Boxing::Unbox<NsString>(valueToConvert);
			result = Boxing::Box<NsString>(Localisation::GetLocalised(sourceString));
			converted = true;
		}
	}

	return converted;
}
I then reference the value converter via a binding in the XAML as follows.
<Label Content="{Binding <<DataBoundValue>>, Converter={StaticResource localise}"/>
Where my approach falls apart is when I have to localise strings that are not bindable objects. I've resorted to a hack to solve this issue where I pass the string to the value converter using the 'ConverterParameter' attribute.
<Label Content="{Binding Converter={StaticResource localise},ConverterParameter=UnlocalisedString}"/>
I'm not proud of this hack. Is there a simpler way to call my localise function from XAML?
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: NOESIS Samples - Localization and language specific fonts

16 Jan 2020, 12:36

Using a converter like you did is a good option because lets you localize bound values and explicit strings (via the ConverterParameter).

There are other approaches you can read about in this thread: viewtopic.php?f=3&t=1574
 
asusralis
Posts: 152
Joined: 30 Jul 2018, 05:03

Re: NOESIS Samples - Localization and language specific fonts

18 Dec 2020, 02:39

Sorry to bump this thread, but I had the same idea with using a converter. Is there any way to update all bindings that use the loc converter? My loc service has a static event I can listen to, but I'm not sure if you could with just a converter. I think I could create a behavior that does this, but then I need to attach a behavior to almost every TextBlock. Is there a better way to do this without explicitly defining localizations in xaml?
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: NOESIS Samples - Localization and language specific fonts

18 Dec 2020, 12:37

Bindings are reevaluated when the source property notifies of changes, even if property didn't really change.
Can you use that to trigger the update?
<TextBlock Text="{Binding Localization, Converter={StaticResource localize}, ConverterParameter=TEXTID1}"/>
In this example everytime you raise the PropertyChanged event in your view model for the "Localization" property it will evaluate the binding and call the converter.
 
asusralis
Posts: 152
Joined: 30 Jul 2018, 05:03

Re: NOESIS Samples - Localization and language specific fonts

18 Dec 2020, 18:08

Is there any way to bind this to something static that could be notified? I was trying to keep all of this out of my view models.
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: NOESIS Samples - Localization and language specific fonts

18 Dec 2020, 18:28

Localization can be a property in some base class of your view models that just returns a static object:
public ViewModelBase : INotifyPropertyChanged
{
  public object Localization { get { return LocalizationManager.Localization; } }
}
That base view model can hook to the static event you mentioned before, and raise the PropertyChanged for the Localization property to trigger the update of all localized bindings.
 
samc
Posts: 94
Joined: 21 Aug 2019, 19:22

Re: NOESIS Samples - Localization and language specific fonts

05 Dec 2025, 00:26

Hello,

Our localization sample sets the fonts in the root of MainWindow.xaml:
FontFamily="./#Oxygen, ./#FontopoNIHONGO"
When specifying multiple fonts in a FontFamily, characters are rendered using the first font in the list that contains the corresponding glyph.
In this sample, when writing English/French, all latin characters can be fond inside Oxygen font. When writing Japanese, the characters are found inside FontopoNIHONGO font.

If your game wants to use different fonts for different parts of the UI you can set the FontFamily property as explained in our Text tutorial. Is that what you need?
I've been specifying my fonts with fallbacks, like this:
<FontFamily x:Key="Font.Family.Tiller">
        /Assets/UI/Fonts/#Tiller,
        /Assets/UI/Fonts/#Noto Sans JP,
        /Assets/UI/Fonts/#Noto Sans KR,
        /Assets/UI/Fonts/#Noto Sans SC,
        /Assets/UI/Fonts/#Noto Sans TC,
    </FontFamily>
    <FontFamily x:Key="Font.Family.Body">
        /Assets/UI/Fonts/#Source Sans 3,
        /Assets/UI/Fonts/#Noto Sans JP,
        /Assets/UI/Fonts/#Noto Sans KR,
        /Assets/UI/Fonts/#Noto Sans SC,
        /Assets/UI/Fonts/#Noto Sans TC,
    </FontFamily>
This has been working ok, but now I'm getting some bug reports that Chinese characters are being rendered with the Japanese or Korean font.

I hopped onto gemini and asked it what to do, and it said this:
This is a classic problem in typography and software localization known as Han Unification.

The issue is not necessarily with your fonts, but with how Unicode works. In Unicode, if a character has the same historical origin and meaning (like "Bone" 骨 or "Grass" 草), it is assigned the same Unicode code point (e.g., U+9AA8), even if it looks slightly different in Japanese, Traditional Chinese, and Simplified Chinese.

Because your XAML checks the Japanese font first, it finds U+9AA8, sees that the font supports it, and renders the Japanese style glyph. It never reaches the Chinese fonts down the list.
Is this accurate? I was hoping that I could just strip character ranges from the font, but if there are truly shared unicode characters across korean, japanese, and chinese, then that's not going to work..

What is the best way to accomplish this? Is there a way to change the precedence based on current locale of the user?

thanks,
sam
 
User avatar
jsantos
Site Admin
Posts: 4822
Joined: 20 Jan 2012, 17:18
Contact:

Re: NOESIS Samples - Localization and language specific fonts

05 Dec 2025, 15:58

Hey Sam,

Yes, that is accurate. Your Japanese glyphs could be blocking your Chinese glyphs, and vice versa.

There is a ticket for addressing this with composite fonts (#2380) but it is not a trivial solution.

A valid workaround is to edit your fonts and remove unnecessary changes.

Who is online

Users browsing this forum: No registered users and 7 guests