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?

Tags:
 
User avatar
sfernandez
Site Admin
Posts: 1778
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: 1778
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

Who is online

Users browsing this forum: No registered users and 13 guests