Subforum with different language (help wanted)


(tnt bom bom) #1

i want to ask if its possible to solve this problem that im facing with discourse when i use 2 languages inside it (multi-support section with different languages)

now the default forum language is English. now when i open the subforum or another section with different language lets say Arabic for example , the problem is this:-

the visitors to that section cant read the subjects because the forum is in english language but the subjects there r in arabic language so writing style going to be Right to Left (which is in english) instead of Left to Right (which is in arabic).

the only way to solve this (which i found) , that the visitor must register in the forum and then go to his settings and change the default language to arabic and enter that arabic section again in order to read the arabic topics.

well is there away that if the visitor can open the arabic section link , then it will show the arabic language style only instead of the default forum language style ?

this is the main forum:-

this is the arabic subforum


(Simon Cossar) #2

A plugin like this might work for you. It’s checking the request path to see if you are on the category page /c/arabic or if you are on a topic page that has the english word ‘arabic’ in the title - ‘(arabic)’ (in brackets) will work. If so, it sets the local to ‘ar’ and displays the page right-to-left.

People will have to refresh the page to get the rtl stylesheet, and refresh it again when they go back to wanting a ltr stylesheet.

# name: arabic-topics
# about: set locale for specific topics and categories

after_initialize do

  ApplicationController.class_eval do

    def set_locale
      if /^\/c\/arabic/.match(request.path) || /^\/t\/arabic/.match(request.path)
        I18n.locale = 'ar'
      else
        if !current_user
          if SiteSetting.set_locale_from_accept_language_header
            I18n.locale = locale_from_header
          else
            I18n.locale = SiteSetting.default_locale
          end
        else
          I18n.locale = current_user.effective_locale
        end
      end
      I18n.ensure_all_loaded!
    end
    
  end
end

I don’t know Arabic. Those are random letters :stuck_out_tongue:

Maybe it will be possible to append the word ‘Arabic’ to any topic created in the arabic category. I can look at this some more later if you think this approach makes sense.

Edit: it looks like there is a more straightforward way to do this. I’ll try making something for it tomorrow.


(Simon Cossar) #3

Here’s a plugin that will localize any category that is named after a locale, to that locale.

For example, if you create a category called ‘ar’ all its topics and category lists will be localized to ‘ar’ and be displayed rtl. To see the change in the locale you have to refresh your browser. Possibly, when the locale changes there should be a notice that lets people know they need to refresh their browser to see it.

The basic logic is:

      category_sym = @category.name.to_sym
      if I18n.available_locales.include? category_sym
        I18n.locale = category_sym
      end

This hasn’t been tested very much, I think the idea is sound, but there could still be some problems.


(tnt bom bom) #4

thnx alot , it is was really helpful.

now u can check the different :-

original forum language (english):-

subforum language (arabic):-