Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
I m working on validation of my portal which is two languages English and french. I want to specify lang attribute in the tag. (i.e .....localhost:40630/?lang=fr) IS there any way to fetch the lang value form URL and place it into HTML lang attribute.

My application is in MVC4 razor engine.
i want some thing like this dynamically when corresponding language choosen its source code would display..........
<html lang="en" xml:lang="en">
or
<html lang="es" xml:lang="es">
Posted
Comments
Sergey Alexandrovich Kryukov 6-Nov-14 13:24pm    
Yes, you can do it, but how can it help making a portal bilingual? Whatever you do, you need to have a translation from one language to another.
—SA
ssharma21 6-Nov-14 14:06pm    
its all developed...nd working ...but for its validation, i need to specify the lang attribute to html tag....can u please tell me how can I do that for two languages?
Nelek 6-Nov-14 15:02pm    
if you want french... why are you putting spanish as the second option?
ssharma21 6-Nov-14 15:18pm    
that was jst an example.
Sergey Alexandrovich Kryukov 6-Nov-14 15:47pm    
Please reply not to your own post, but to the comments by the people who you want to address. Can you see the "Reply" buttons. As you comment to your own post, we don't get notifications on your comment.
Besides, you did not answer my question. So, what's the point in specifying that attribute?
—SA

1 solution

Something like this:

XML
<html>
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"/>

        <script type="text/javascript">
            $(document).ready(function() {
                var language = "en" //Read from query string...
                $("html").attr("lang", language);
            });
        </script>

    </head>
    <body>
    </body>
</html>


See here on how to read query string in JavaScript:

http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript[^]
 
Share this answer
 
Comments
Maciej Los 6-Nov-14 16:33pm    
+5
Manas Bhardwaj 6-Nov-14 16:38pm    
thx!
ssharma21 7-Nov-14 11:45am    
thanks for the code manas...m trying to fix it. but is it also possible to specify lang attribute widout fetching it from url... my portal is in two languages...english and french.. nd i want something lyk dis... <html lang="en" xml:lang="en"> or <html lang="fr" xml:lang="fr"> whichever language is using at dat tym.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900