Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Anthony Candaele 1197 posts 2049 karma points
    Nov 10, 2012 @ 15:29
    Anthony Candaele
    0

    programmaticaly detecting language version

    Hi,

    Currently I'm working on a multilanguage website (en - he)

    Because the Hebrew language reads right to left (RTL) I need to reverve the field columns of a table that is programmaticaly generated (in Razor).

    So the heading columns "Name", "Value" should reverse order to "Value", "Name" when the Hebrew version of the page is shown.

    Therefore my question, I there a way to programmaticaly determine the language context in which the page is shown?

    Thanks,

    Anthony

  • Anthony Candaele 1197 posts 2049 karma points
    Nov 10, 2012 @ 15:48
    Anthony Candaele
    0

    Found the solution:

    just query for the root of the current page:

    var root = Model.AncestorOrSelf.Where("NodeTypeAlias == \"Homepage\"");

    Then you can conditionally generate the table with the columns in the right order:

    if (root.Name == "en-Us")

        {

            <table>

    <tr>

    <th>@Dictionary["name"]</th><th>@Dictionary["value"]</th>

    </tr>

    <tr>

    <td>@Dictionary["Full Name"]:</td><td>@formModel.FullName</td>

    </tr>

    <tr>

    <td>@Dictionary["Email"]:</td><td>@formModel.Email</td>

    </tr>

            <tr>

                <td>@Dictionary["Your question"]:</td>

                <td>@formModel.Question</td>

            </tr>        

    </table>

        }

    Hope this code can help others who are building multilingual websites.

    Anthony

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Nov 10, 2012 @ 16:02
    Jan Skovgaard
    0

    Hi Anthony

    Is the name of your root nodes for each language the language code, like en-Us?

    /Jan

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Nov 10, 2012 @ 16:19
    Chriztian Steinmeier
    2

    Hi Anthony,

    Are you aware of the dir attribute in HTML?

    If you set that to "rtl" on a table (or probably better on the html/body tag, since the entire page is mort likely supposed to be served that way), the browser reverses the order of the columns...

    /Chriztian

  • Anthony Candaele 1197 posts 2049 karma points
    Nov 10, 2012 @ 16:36
    Anthony Candaele
    0

    Hi Chriztian,

    Thanks a lot for the tip. I tested it out with the css attribute direction:rtl; and it works fine :)

    greetings,

    Anthony

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Nov 10, 2012 @ 16:40
    Jan Skovgaard
    1

    Hi Anthony

    I'm still curious about my previous question since I think we miss some kind of extension/helper (depending if you're using Razor or XSLT) that can return the selected culture of the root node - so I'm guessing what you're doing is just naming the root nodes according to the sites culture, right? It's not razor that returns the selected culture on the root node?

    Usually when I need this I add a setting on the root node, where the language can be selected. But it's a bit annoying and would be awesome if we could just get it returned from the setting we have already made :)

    /Jan

  • Anthony Candaele 1197 posts 2049 karma points
    Nov 10, 2012 @ 16:46
    Anthony Candaele
    0

    Hi Jan,

    Yes, my rootnodes are named after my language settings:

    en-Us (hostname: localhost/en-us)

    he-IL (hostname: localhost/he-il)

    I think this helper method for determining the culture of the rootnode would be a very good idea, as it would make it unnessery to query for it in Razor or Xslt.

    greetings,

    Anthony

Please Sign in or register to post replies

Write your reply to:

Draft