Dmitrii Polianskii
Dmitrii Polianskii

Reputation: 575

TxTranslation WPF application

I wanna use this library to localize my application. I really like their tool to edit files and It looks like it esy to use. I've created tsd file and It looks right but It doesn't work inside app.

My txd file to localize application

The version of library

    `<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" />

Upvotes: 0

Views: 210

Answers (2)

Dmitrii Polianskii
Dmitrii Polianskii

Reputation: 575

I don't know why there's no extension in Tx library in order to convert whole string to the upper case string but this is true. I have created this extension by myself. Here's the code may be it'll help somebody.

/// <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
}

And inside of the extension I'm using my own class TxService where I have just added all the same methods which there're in the original Tx class for UT abbreviation.

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();
    }
}

Upvotes: 0

ygoe
ygoe

Reputation: 20404

Your code works perfectly. You just shouldn't set the text foreground colour to white on a white background. ;-)

And you should review your dictionary. The text keys look weird. See my comment above.

Upvotes: 1

Related Questions