We build. You grow.

Get best community software here

Start a social network, a fan-site, an education project with oxwall - free opensource community software

Custom elements depending on the selected language | Forum

Thomas
Thomas Jun 19 '13
I've added custom HTML on my homepage. I would like it to be changed depending on the language the user chooses. Is it possible?
ross Team
ross Jun 19 '13
Do you mean text translation?
Thomas
Thomas Jun 19 '13
Yeah. I have some information for my users that I want to change depending on what language the user is setting or where he is coming from.
ross Team
ross Jun 19 '13
Unfortunately, it is not possible. 
Thomas
Thomas Jun 19 '13
How about static pages? Is that doable? I can set a redirect in .htaccess file as follows:


#The 'Accept-Language' header starts with 'se'

#and the test is case-insensitive ([NC])

RewriteCond %{HTTP:Accept-Language} ^se [NC]

#Redirect ui language to Swedish (language id is '4')

#sending 301 (Moved Permanently) HTTP status code

RewriteRule ^$ /?language=4 [L,R=301]


#For every other language (including English :)) use English (language id is '1')

RewriteRule ^$ /?language=4 [L,R=301]


But I have this translation problem.... :-(

ross Team
ross Jun 19 '13
We do not recommend to do that in .htaccess. 


Please, try this solution: 
Use Javascript code to show a certain block of the custom HTML widget where text translations in different languages are, when a user select a certain language with the assistance of the GET parameter or block ID

Thomas
Thomas Jun 19 '13
Can you explain that a little more? Perhaps a code example? It would be very appreciated. 
ross Team
ross Jun 19 '13
Please, go to the custom code modification section of the forum, our staff will try to help you. 
Thomas
Thomas Jun 20 '13
Oki. Thx. :-)
Thomas
Thomas Jun 20 '13
I solved it. I simply use a variable and a if .. else .. statement


var lang = document.getElementsByTagName("html")[0].getAttribute("lang");


when a user changes the language, the system automatically changes the html tag and lang variable to the current language. In my case to "se-SV"


<script>


if (lang == "sv-SE")

{

/* do the right thing in Swedish*/

}


else

{

/* do the right thing in English */

}

</script>


It works for me. ;-)

ross Team
ross Jun 25 '13
Great!
Marcus
Marcus Nov 26 '14
Could you please post a full code? Like with text in English and Spanish?
Lucas
Lucas Jan 5 '15
ALSO FOR ME. THANKS, LUCAS
ross Team
ross Jan 5 '15
Topic was moved from General Questions.
W.SNEIJDER
W.SNEIJDER Nov 1 '15
Thomas I did not understand. The code should be written in custom html widget ?