我想使用这个库来本地化我的应用程序。我真的很喜欢他们编辑文件的工具,它看起来像是使用它。我已经创建了tsd文件,它看起来正确,但它在应用程序内部无效。
My txd file to localize application
库的版本
`<package id="Unclassified.TxLib" version="1.184.37" targetFramework="net45" />`
xmlns:Tx="http://unclassified.software/source/txtranslation"
.......
<TextBlock
x:Uid="HomePage_Title"
Name="txtTitle"
Foreground="White"
FontWeight="Bold"
FontSize="32"
Padding="30"
Text="{Tx:UT Key=homepage.title}"
HorizontalAlignment="Center" />
答案 0 :(得分:1)
您的代码完美无缺。您不应该在白色背景上将文本前景色设置为白色。 ; - )
你应该检查一下你的字典。文本键看起来很奇怪。请参阅上面的评论。
答案 1 :(得分:0)
我不知道为什么在Tx库中没有扩展名来将整个字符串转换为大写字符串但这是真的。我自己创建了这个扩展。这里的代码可能会对某人有所帮助。
/// <summary>
/// Markup extension providing the Tx.UT method functionality.
/// </summary>
public class UATExtension : TExtension
{
#region Constructors
/// <summary>
/// Initialises a new instance of the UATExtension class.
/// </summary>
public UATExtension()
: base()
{
}
/// <summary>
/// Initialises a new instance of the UATExtension class.
/// </summary>
/// <param name="key">Text key to translate.</param>
public UATExtension(string key)
: base(key)
{
}
/// <summary>
/// Initialises a new instance of the UATExtension class.
/// </summary>
/// <param name="key">Text key to translate.</param>
/// <param name="count">Count value to consider when selecting the text value.</param>
public UATExtension(string key, int count)
: base(key, count)
{
}
/// <summary>
/// Initialises a new instance of the UATExtension class.
/// </summary>
/// <param name="key">Text key to translate.</param>
/// <param name="countBinding">Binding that provides the count value to consider when selecting the text value.</param>
public UATExtension(string key, Binding countBinding)
: base(key, countBinding)
{
}
#endregion Constructors
#region Converter action
/// <summary>
/// Provides the T method in specialised classes.
/// </summary>
/// <returns></returns>
protected override Func<string, int, string> GetTFunc()
{
return TTx.UAT;
}
#endregion Converter action
}
在扩展内部我正在使用我自己的类TxService,其中我刚刚添加了原始Tx类中所有相同的方法,用于UT缩写。
public static class TxService
{
#region UAT overloads
/// <summary>
/// Combined abbreviation for the UpperCase and Text methods.
/// </summary>
public static string UAT(string key)
{
return UA(Tx.T(key));
}
/// <summary>
/// Combined abbreviation for the UpperCase and Text methods.
/// </summary>
public static string UAT(string key, int count)
{
return UA(Tx.T(key, count));
}
/// <summary>
/// Combined abbreviation for the UpperCase and Text methods.
/// </summary>
public static string UAT(string key, decimal count)
{
return UA(Tx.T(key, count));
}
/// <summary>
/// Combined abbreviation for the UpperCase and Text methods.
/// </summary>
public static string UAT(string key, params string[] data)
{
return UA(Tx.T(key, data));
}
/// <summary>
/// Combined abbreviation for the UpperCase and Text methods.
/// </summary>
public static string UAT(string key, Dictionary<string, string> data)
{
return UA(Tx.T(key, data));
}
/// <summary>
/// Combined abbreviation for the UpperCase and Text methods.
/// </summary>
public static string UAT(string key, int count, params string[] data)
{
return UA(Tx.T(key, count, data));
}
/// <summary>
/// Combined abbreviation for the UpperCase and Text methods.
/// </summary>
public static string UAT(string key, int count, Dictionary<string, string> data)
{
return UA(Tx.T(key, count, data));
}
/// <summary>
/// Combined abbreviation for the UpperCase and Text methods.
/// </summary>
public static string UAT(string key, decimal count, params string[] data)
{
return UA(Tx.T(key, count, data));
}
/// <summary>
/// Combined abbreviation for the UpperCase and Text methods.
/// </summary>
public static string UAT(string key, decimal count, Dictionary<string, string> data)
{
return UA(Tx.T(key, count, data));
}
#endregion UT overloads
/// <summary>
/// Abbreviation for the <see cref="UpperCaseAll"/> method.
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
public static string UA(string text)
{
return UpperCaseAll(text);
}
/// <summary>
/// Transforms the first character of a text to upper case.
/// </summary>
/// <param name="text">Text to transform.</param>
/// <returns></returns>
public static string UpperCaseAll(string text)
{
if (string.IsNullOrEmpty(text)) return text;
return text.ToUpper();
}
}