• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Language Attribute

Ray

Active member
#1
How can I set different language attributes for different forums/threads?

The default one is lang="en-US" , I have 3 subforums that contain threads in French only ( lang="fr-FR" ).

I was thinking of editing the PAGE_CONTAINER template as follows:

<xen:if is="!in_array({$thread.node_id}, array(70,71,72))">
<html id="XenForo" lang="{$visitorLanguage.language_code}" class="Public {xen:if {$visitor.user_id}, 'LoggedIn', 'LoggedOut'}" xmlns:fb="http://www.facebook.com/2008/fbml">
<xen:else />
<html id="XenForo" lang="fr-FR" class="Public {xen:if {$visitor.user_id}, 'LoggedIn', 'LoggedOut'}" xmlns:fb="http://www.facebook.com/2008/fbml">
</xen:if>
but doing this will make the entire line of code disappear from non-thread pages. :sick:

Thanks in advance!
 

Jake Bunce

XenForo moderator
Staff member
#2
You can't just change the html tag. The language needs to be properly set or selected so the appropriate phrases are loaded.

There is no option to set a language on a per-forum basis. There is only the default language, plus the option for users to select their own language (which applies to all forum pages). Normally you would set the most commonly used language as the default. Then ask your users to select the other language if they so desire.

An addon is required to set a language on a per-forum basis. If you are a programmer then you can post in the Development Questions forum for help with this. Or post an Add-on Request and some one may be able to write this for you.
 

Ray

Active member
#3
You can't just change the html tag. The language needs to be properly set or selected so the appropriate phrases are loaded.
...
Normally you would set the most commonly used language as the default. Then ask your users to select the other language if they so desire.
You are right, users can choose whatever language they want as long as said languages are available to them, but I am not referring to the forum languages(phrases).

For example, if users from France search for "bill gates" via google.fr, they will only get results that are written in French. If they search for "bill gates" via google.com, they will get results that are written in English. The lang attribute instructs Google Search to display the content to only those who are looking for it in that specific language.

The three subforums in question contain articles and discussions that English-speakers simply aren't looking for, but are very useful and important to those who speak French or are from France.

Currently, if a user searches for my content written in French via google.com, they will find it. If the same user repeats the process via google.fr, they simply won't find it, as the content is irrelevant to their location (fr-FR)

---------------

I was hoping this could be done with some conditionals; set the lang attribute so that it only affects threads located under those specific subforums.
 

Jake Bunce

XenForo moderator
Staff member
#4
The lang attribute instructs Google Search to display the content to only those who are looking for it in that specific language.
Hmm, I didn't know that.

I was hoping this could be done with some conditionals; set the lang attribute so that it only affects threads located under those specific subforums.
Thread and forum records are not normally available to PAGE_CONTAINER. You will need to pass those values using xen:container per Kier's post.

Edit these templates:

Admin CP -> Appearance -> Templates
> forum_view
> thread_view


Add this line to the top of each template:

Code:
<xen:container var="$forumId">{$forum.node_id}</xen:container>
Then edit this template:

Admin CP -> Appearance -> Templates -> PAGE_CONTAINER

Use this condition in place of the language code:

Code:
{xen:if 'in_array({$forumId}, array(1,2,3))', 'fr-FR', '{$visitorLanguage.language_code}'}
1,2,3 is a comma list of forumids for your French subforums.
 
#5
I started a forum for musicians in polish language few weeks ago and I want to improve in one or two Categories with a select button of two languages: english and polish.
Is it possible?
Should I ask a question at AddOn Request?
 

TrevC

Well-known member
#7
Hi Jake.

I'm currently using your StyleOverride code addition (working great, thanks!).

Do you happen to know if it's possible to force a specific language based on which domain the visitor is accessing the forum from?

I tried the obvious, setting ["language_id"] in the conditional (just like the style). It seems like it should work.; Dumping $visitor's output shows the correct language number is selected, but none of it seems to take effect.

Is this simply not possible? I sure hope there's a way to hack it together and make it happen.

Cheers
 

Jake Bunce

XenForo moderator
Staff member
#8
Hi Jake.

I'm currently using your StyleOverride code addition (working great, thanks!).

Do you happen to know if it's possible to force a specific language based on which domain the visitor is accessing the forum from?

I tried the obvious, setting ["language_id"] in the conditional (just like the style). It seems like it should work.; Dumping $visitor's output shows the correct language number is selected, but none of it seems to take effect.

Is this simply not possible? I sure hope there's a way to hack it together and make it happen.

Cheers
Use:

Code:
$visitor->setVisitorLanguage(5);
Specify the language_id. That should do it.

There is extra stuff to set when you change the language, and this function takes care of it