locked
multiple ways to use resource files to build complex hyperlinks, which one is best RRS feed

  • Question

  • User-1246604461 posted


    I have this hyperlink, with title tags, image wrapped in it and alt tags that I want to be available in multiple languages:

        <a href="/muziek/zoeken" title="muziek"><img title="muziek" alt="muziek" src="images/category_artists.png" /></a>  
       
    I'm now wondering what the best way is to make this translation with resource files.


    As I see it I have a couple of options:

    OPTION 1:
    Place the entire code in a resource file:

    default.aspx.en.resx:
        link    <a href="/music/search" title="music"><img title="music" alt="music" src="images/category_artists.png" /></a>  

    default.aspx.nl.resx:
        link    <a href="/muziek/zoeken" title="muziek"><img title="muziek" alt="muziek" src="images/categorie_muziek.png" /></a>  

    And then place a literal in the HTML:
        <asp:Literal ID="Literal3" Text="<%$Resources:link %>" runat="server"/>

    But somehow this seems like a route that is not optimal.
    For instance: I could way better do something like this in HTML, where I can just insert:

    <a href='/<%$Resources:music %>/<%$Resources:search %>' title='<asp:Literal ID="Literal3" Text="<%$Resources:music %>" runat="server"/>'><img title='<asp:Literal ID="Literal3" Text="<%$Resources:music %>" runat="server"/>' alt='<asp:Literal ID="Literal3" Text="<%$Resources:music %>" runat="server"/>' src="images/category_artists.png" /></a>  


    OPTION 2
    place code in server side tags:
            <asp:HyperLink ID="HyperLink1" NavigateUrl="<%$Resources:music_url_search%>" ToolTip="<%$Resources:music%>" runat="server">
                <asp:Image ID="Image1" ToolTip="<%$Resources:music %>" AlternateText="<%$Resources:music %>" ImageUrl="images/category_artists.png" runat="server" />
            </asp:HyperLink>

    OPTION 3: build the hyperlink dynamically in code behind (perhaps less maintanance intensive?)

    <asp:Literal ID="ltMusic" runat="server"/>

    ltMusic.Text = String.Format("<a href=""{0}"" title=""{1}""><img title=""{1}"" alt=""{1}"" src=""images/category_artists.png"" /></a>", rm.GetString("music_url_search"), rm.GetString("music"))
           
           
    What are the pros and cons other people experiences with the above methods? In other words: which one would YOU pick and why?

    Or are there far better ways to handle this?   

    Thanks!

    Tuesday, May 3, 2011 4:23 AM

Answers

  • User377791177 posted

    Your option two is much better and falls inside the best practice region's capital.

     

    At the same time you needn't write that OMG code in your option two. you can just place your server control normally with an additional

    meta tag "meta:resourcekey="HyperLinkResource""

    Rest will be taken care of by the framework u just need to specify the properties in teh resx.

    so my page.aspx.resx has the following for the imagebutton

    HyperLinkResource.ImageUrl="url"

    HyperLinkResource.Width=100%

    HyperLinkResource.Text="text in language"

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 3, 2011 4:34 AM

All replies

  • User377791177 posted

    Your option two is much better and falls inside the best practice region's capital.

     

    At the same time you needn't write that OMG code in your option two. you can just place your server control normally with an additional

    meta tag "meta:resourcekey="HyperLinkResource""

    Rest will be taken care of by the framework u just need to specify the properties in teh resx.

    so my page.aspx.resx has the following for the imagebutton

    HyperLinkResource.ImageUrl="url"

    HyperLinkResource.Width=100%

    HyperLinkResource.Text="text in language"

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 3, 2011 4:34 AM
  • User-1246604461 posted

    Thanks! My image control now looks like: <asp:Image ID="imgLogo" meta:resourcekey="imgLogo" runat="server" />

    Thursday, May 5, 2011 11:58 AM