Provides interfaces and classes to build translations for .NET projects. Translation repository is based on key-value structure.
-
ITranslationHolder
interface of object, that holds translated texts. It exposesTryGetTranslation
method for getting text andOnChangeTranslations
event. -
ILocalTextSource
interface is base text provider. It exposesValue
property that holds current translation. Classes that implementILocalTextSource
are also 'INotifyPropertyChanged' soValue
property can be bind in visual models i.e. WPF.-
LiteLocalTextSource
: simple class, connected toITranslationHolder
that exposes single translated text. It reacts for language changes. -
ParametricLocalTextSource
: Allows to construct text similar tostring.Format
where format is connected to translation sources. It updatesValue
property each time translation or parameter (if implementsINotifyPropertyChanged
) is changed. -
FormattedLocalTextSource
: Similar toParametricLocalTextSource
but not react to parameters changing. It also provides default translation used whenITranslationHolder
is not connected or doesn't contains tranlation for given key.
-
var mySrc = new FormattedLocalTextSource("Open {0}", "App.Translation.Open", description);
This creates mySrc
object that excposes text calculated from "Open {0}"
template and parameter from description
variable. If translation holder is connected and it contains text for "App.Translation.Open"
key then translation from holder is used instead of "Open {0}"
template.
Assume we have AppTranslations
with static field StrOk
.
public static class AppTranslations {
/// <summary>
/// Text: O.K.
/// </summary>
public static readonly ILocalTextSource StrOk
= new LiteLocalTextSource("Common.Ok");
}
It's possible to bind TextBlock.Text
property to Value
property exposed by StrOk.
<TextBlock>
<TextBlock.Text>
<Binding Path="Value" Source="{x:Static app:AppTranslations.StrOk}" Mode="OneWay"/>
</TextBlock.Text>
</TextBlock>
Nuget iSukces.Translation contains signed assemblies, but signing key is not privided in source repository. You can generate your own key or rid off signing.