Localized categories plugin

A plugin to set a category’s locale based off it’s slug.

This plugin allows you to set the locale for individual categories by basing the category slug off the locale’s language code. For example, for Persian set the category’s slug to fa-ir. The locale will be applied to the category and to its subcategories.

When the locale changes, the new locale is automatically reloaded. For non-locale categories, the locale is reset to either the site’s default locale, or the user’s preferred locale.

Todo: get the locale off the http headers for non-logged in users.

The plugin works, but is still under development. If you are interested in using it on a ‘serious’ website, get in touch with me.

The categories page is displayed in either the site’s default locale or the user’s preferred locale:

The category page for localized categories uses the category’s locale:

This is shown when the locale is being updated. The text should probably be replaced with some kind of graphic:

7 Likes

this is great :grinning:

i’d love to try it, and will update about the ups and downs.

2 Likes

If you try it make sure to use the latest version.

1 Like

just found the time to start testing, cool and useful especially for non-English forums.

meanwhile,

  • after i activated the plugin and named a folder-slug into en, i got errors with this log:
    subcat.txt (4.8 KB)
    and after i remove the topic list preview, everything comes back to normal. is there a way to have both plugins?

  • after i changed the local from fa_IR to en in the user setting, the site couldn’t be loaded, and kept on the message: “The site locale is being updated”. until i changed the user local from en to fa_IR again. error log:
    err2.txt (1.9 KB)

Yes, I ran into the same problem yesterday! I’ll try to fix that this afternoon.

Do you have ‘set locale from accept language header’ set to true? I assumed that was what was causing the problem.

1 Like

It’s working now for when there are user set locales and for when ‘set locale from accept language header’ is true. I still want to change the way it is loading the locales.

You can try it out here: http://constructivelearningspace.com/
We’re trying to set up an informal group for teaching/learning Persian. It’s just getting started. (I’m still trying to find the letters on the keyboard :slight_smile: )


edit: I’ve changed the plugin so that it does not switch the locales for anonymous users. This is because I am using it on a forum where I have the setting ‘set locale from accept language header’ set to true. (Although I have limited it for now to only accept ‘en’, ‘fr’, and ‘fa-IR’). The reason for using this setting is to allow users to sign up for the site in the language they are most comfortable in. The problem this creates for the plugin is that it needs to know what language to switch back to when it is leaving a localized category.

3 Likes

that’s cool, i think i may be able to be handy there :wink: though you should tolerate the way i use English!

i just signed up there, and will participate in the discussion hopefully tonight :smiley:

1 Like

This plugin also translates the topic etc? Or only a name category?

It forces the site locale to change. That has the same effect as when you change the locale in your user preferences on sites that allow user locales to be set - it translates the user interface, but not the content of posts.

4 Likes

I haven’t looked at this for a while. Get in touch with me if you are going to enable it on a production site.

is the plugin still available in “constructive-learning-space” ? as I couldn’t see it working there.

No, but I’m going to try adding it back right away. I took off because I was using the forum to test something.

I am looking into setting up a multi-language site (English/Chinese) and am wondering if this plugin works with the latest discourse versions or if there is a better way to enable a multi-language site?

No, it doesn’t work.

Have a look at this topic for a few ideas: How to structure a multilingual community.

For the case of a forum where users are unlikely to be able to understand the site’s default locale, probably the most important thing is to make sure the user’s locale set correctly when they create their account. That way they will be able to navigate the forum, even if they can’t read some of the content. To do this, first make sure that the allow user locale Site Setting is enabled. When enabled, users will be able to set their locale on their preferences page.

Having to set the locale preferences on a site where users can’t understand the default locale could be difficult. There are two options I know of to get around this. You can either use SSO and set the locale with an SSO parameter, or enable the set locale from accept language header Site Setting.

Note: There is an issue with setting the locale for anonymous users for on sites that are using a CDN. It can cause the wrong locale files to be served to anonymous users. See: Swedish? meta just showed me the UI in Swedish .

3 Likes