translation resource directionary
How would you suggest handling translations. It seems the recommended way is a resource dictionary and something like
Now this works well enough for all static text but a lot of text in a game is dynamically supplied via binding. It seems to be impossible to trigger resource lookups via binding. So this leads to having two sperate translation tables in two places. Not an optimal solution. Is there anything that would support a better solution.
Kind of in the same category is my other problem, giving a button a custom color via binding. Something I haven't been able to figure out. Of course it is possible to work with triggers. On a table that can have 4 colors I can work with something like this
But imagine this table
Every column is supposed to have their own color and the buttons are toggleable. That would create about 50-60 triggers per button for a few hundred buttons. I don't believe that is feasible. Since those buttons already have their own classes and bindings in the model the easiest way would be to provide a color binding but that doesn't seem to exist in XAML.
Code: Select all
<TextBlock Text="{StaticResource prefix-key}"></TextBlock>
Kind of in the same category is my other problem, giving a button a custom color via binding. Something I haven't been able to figure out. Of course it is possible to work with triggers. On a table that can have 4 colors I can work with something like this
Code: Select all
<Style.Triggers>
<DataTrigger Binding="{Binding Activity}" Value="N">
<Setter Property="Background" Value="{StaticResource ActivityNoneBrush}"/>
</DataTrigger>
<DataTrigger Binding="{Binding Activity}" Value="E">
<Setter Property="Background" Value="{StaticResource ActivityEatBrush}"/>
</DataTrigger>
<DataTrigger Binding="{Binding Activity}" Value="S">
<Setter Property="Background" Value="{StaticResource ActivitySleepBrush}"/>
</DataTrigger>
<DataTrigger Binding="{Binding Activity}" Value="T">
<Setter Property="Background" Value="{StaticResource ActivityTrainBrush}"/>
</DataTrigger>
</Style.Triggers>
Every column is supposed to have their own color and the buttons are toggleable. That would create about 50-60 triggers per button for a few hundred buttons. I don't believe that is feasible. Since those buttons already have their own classes and bindings in the model the easiest way would be to provide a color binding but that doesn't seem to exist in XAML.
-
sfernandez
Site Admin
- Posts: 2997
- Joined:
Re: translation resource directionary
For translation, if the text comes from a Binding, won't be possible to provide the translated text directly from the view model? Or maybe the view model is just returning a text ID you want to translate? In that case you can use a Converter that gets that ID and translates to the appropriate text:
And for the brushes the best option here is also using a Converter:
Have you tried something like that?
Code: Select all
<TextBlock Text="{Binding Category, Converter={StaticResource TranslateConverter}}"/>
Code: Select all
<Button Background="{Binding Activity, Converter={StaticResource ActivityBrushConverter}}"/>
Re: translation resource directionary
Yes that is possible and is the current way but that means you have two separate lookup sources.For translation, if the text comes from a Binding, won't be possible to provide the translated text directly from the view model?
No I haven't, guess I really need to look into converters then. Are there any examples for these use cases?... converters ...
-
sfernandez
Site Admin
- Posts: 2997
- Joined:
Re: translation resource directionary
Our Localization sample uses a converter to change the foreground color of some sliders depending on their value:
MainWindow.xaml
LevelToColorConverter.cs
You can have something similar but returning a Brush object instead of a Color, based on the Activity value.
MainWindow.xaml
LevelToColorConverter.cs
You can have something similar but returning a Brush object instead of a Color, based on the Activity value.
Re: translation resource directionary
Sadly that doesn't help much as I'm in the C++ side of things and not in Unity.Our Localization sample uses a converter to change the foreground color of some sliders depending on their value:
MainWindow.xaml
LevelToColorConverter.cs
Re: translation resource directionary
The Localization sample is also available in C++.
Re: translation resource directionary
Ok I think I'm close to the solution.
So this would be the converter
Just some purple test but it fails to compile because of the deleted copy constructor in Noesis::SolidColorBrush. Since you said it would be possible to return a Brush instead of a color what am I missing here?
So this would be the converter
Code: Select all
bool TryConvert( BaseComponent* value, const Noesis::Type* targetType, BaseComponent*, Noesis::Ptr<BaseComponent>& result )
{
if ( targetType == Noesis::TypeOf<Noesis::Brush>() )
{
auto col = Noesis::Color( 255, 0, 255 );
result = Noesis::Boxing::Box( Noesis::SolidColorBrush( col ) );
return true;
}
return false;
}
-
sfernandez
Site Admin
- Posts: 2997
- Joined:
Re: translation resource directionary
SolidColorBrush is a BaseComponent so you have to return it without boxing:
Code: Select all
bool TryConvert( BaseComponent* value, const Noesis::Type* targetType, BaseComponent*, Noesis::Ptr<BaseComponent>& result )
{
if (targetType == Noesis::TypeOf<Noesis::Brush>())
{
result = MakePtr<Noesis::SolidColorBrush>(Noesis::Color( 255, 0, 255 ));
return true;
}
return false;
}
Re: translation resource directionary
Was a difficult birth as usual and more than I like but in the end it works.
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 52 guests