locked
How to use localization in XAML without using the attribute suffix [uid].[attribute] in the resource file

    Question

  • Hi, 
    Is there a way to NOT specify the attribute in the resource file [uid].[attribute] and just use the uid and in the XAML to specify which attribute the string should go to?

    Resource file: HelloString.Text = "Hello"
    XAML: <TextBlock x:uid="HelloString"/>

    Instead, I want the resource file to have just the UID as the key.
    Resource file: HelloString = "Hello"
    And in the XAML I want this string to be assigned to the text dependency property.
    may be like this <TextBlock Text=x:uid/> 

    The reason behind this is this, say I want to display the same text for a button too, I need to create another string in the resource file as HelloString.Content which is a duplicate.
    I am trying to not have duplicate strings in the resource file.

    Currently I use a converter that takes the UID as the parameter and converts it to the appropriate string from the resource file. Is there a better way to do this?
    Tuesday, May 12, 2015 12:50 AM

Answers

  • No. That's not how the resource system works.

    Your desire to use the same string in different contexts is not recommended. It can interfere with proper localization if the string needs to be translated or inflected differently for the different contexts.

    See the Globalization and localization guidelines for more details.

    Also, please do not put Microsoft in your "I work at" field if you don't work at Microsoft. If you do work at Microsoft please associate your account at https://msdn.microsoft.com/en-us/gg602412.aspx

    Tuesday, May 12, 2015 12:59 AM
    Moderator

All replies

  • No. That's not how the resource system works.

    Your desire to use the same string in different contexts is not recommended. It can interfere with proper localization if the string needs to be translated or inflected differently for the different contexts.

    See the Globalization and localization guidelines for more details.

    Also, please do not put Microsoft in your "I work at" field if you don't work at Microsoft. If you do work at Microsoft please associate your account at https://msdn.microsoft.com/en-us/gg602412.aspx

    Tuesday, May 12, 2015 12:59 AM
    Moderator
  • Thanks Rob. That makes sense.

    And thanks for pointing out that I haven't changed my employer information after I've quit msft :)

    Tuesday, May 12, 2015 1:43 AM