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

Language Attribute

Discussion in 'XenForo Questions and Support' started by Ray, Apr 25, 2011.

  1. Ray

    Ray Active Member

    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:

    but doing this will make the entire line of code disappear from non-thread pages. :sick:

    Thanks in advance!
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    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.
     
  3. Ray

    Ray Active Member

    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.
     
  4. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Hmm, I didn't know that.

    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.
     
    Travis-Mc, EasyTarget and Ray like this.
  5. akysz

    akysz Member

    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?
     
  6. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

  7. TrevC

    TrevC Well-Known Member

    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
     
  8. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    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
     
  9. TrevC

    TrevC Well-Known Member

    Nice one. I'll try this soon. Thanks Jake :)
     

Share This Page