Translating category names
Hi everyone,
I am serving both Korean and English languages on my forum. I am wondering how I can switch the category names depending on which language is currently selected with the Multilingual switch.
What I've tried so far is following the suggestion on this discussion:
http://vanillaforums.org/discussion/18751/can-categories-be-translated-for-localization
So I added this line in my \locales\Korean\definitions.php
$Definition['test category'] = '카테고리 번역';
and added $Category->Name = T($Category->Name);
in \applications\vanilla\models\class.categorymodel.php like so:
public static function AddCategoryColumns($Data) { $Result = &$Data->Result(); $Result2 = $Result; foreach ($Result as &$Category) { $Category->Name = T($Category->Name); if (!property_exists($Category, 'CountAllDiscussions')) $Category->CountAllDiscussions = $Category->CountDiscussions; ...
However, this does not seem to have any effect. When I switch the language to Korean, the category name is still 'test category'.
Apparently the solution above has worked for others so I'm not sure what's different in my case - maybe the new Vanilla version works differently or the place I inserted the code is wrong? I am completely new to PHP.
Could anyone please enlighten me? Or, is there any other way to achieve this?
I am using Vanilla 2.1.3. Thanks for any help in advance.
Comments
Any advice on this issue? I'd appreciate any guidance.
Do you have any whitespace characters in the name?
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
Generally not a good idea to mod the core like this, you will make updating difficult.
This translation won't change the url slug you realise.
The category has to be named as
test category
to translate it. It need to be identical.grep is your friend.
Thank you for the replies!
@hgtonight
Yes, there are spaces in the category name. Could it be the source of the problem? How may I get around it and make this work?
@x00
True, I recognize this is risky and I do regret having to resort to such a method. If there is any safer way to achieve this, I will gladly do that! For the moment, I am getting really desperate about this issue (need to resolve it ASAP), so I'm giving this method a try - the only method I've found.
My category name is indeed
test category
, exactly as shown including case sensitivity. Um, I've been contemplating the url slug thing, but not sure if I understood it correctly? So, the English slug isp=/categories/test-category
and the translated Korean slug will still bep=/categories/test-category
? (If that's the case, I'm still okay with that, as I care most about the displayed name on the forum although the slug translation would be a nice-to-have.)Thanks again to both!
I think that fix won't work no matter what your categories are named.
what i would do - put the korean name (english name) in the category name or vice versa, so you have both NAmes in the category.. So much simpler. and make the font-size of the categories in the panel a bit smaller if need be.
Telling you what files you need to change in the core, would lead down a slippery slope.
Seems like the simplest non-core way to do things.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Hi @peregrine thanks for the advice!
Indeed, just including both names is by far the simplest solution - and the first thing that came to my mind as well! The trouble is, my forum's primary target audience is Koreans who don't understand English and I really want to avoid intimidating them... which is why I've been desperately trying to limit the display of English when in Korean mode.
How invasive would the changes be to get this working? Would you mind, letting me know how to change the files so I can at least try? I use a local SVN repository to manage my Vanilla files, if I really mess it up at least I can revert to the current working state. Your help is sincerely appreciated!
If Koreans are going to be intimidated by posting in English, what are English going to feel posting in Korean?
Maybe best having a separate English language section, then the majority of you SEO linkage will be Korean, which is you core audience anyway.
grep is your friend.
@x00
That is a valid point, but my circumstances are a little... peculiar. My forum is a Korean branch of a much larger organization - and they do, currently, have English-speaking branches such as US, UK, Australia, etc. So the English speaking users have plenty of options, whereas non-bilingual Koreans only have my forum as the source of information. That's why I want to make it as Korean-friendly as possible; because no other branch serves them.
Creating separate English categories is an interesting idea though, thanks for the suggestion! I'll ponder about the possibility.
I think you should add your desire of translated categories as feature suggestion on github. It won't fix the present but it might be added down the road, if vanilla staff deem it worthy.
If a T($Category->Name) were added everywhere the category name is displayed in views etc. It would be a start.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
@peregrine
Oh I see, I had no idea it had to be added in multiple places! That gives me hope, thank you so much. I will try that and see if it works.
I also just signed up for Github and created an Issue for this. Is it correct that feature requests go in here? http://github.com/vanilla/vanilla
My request ticket is: https://github.com/vanilla/vanilla/issues/2159
This is my first time using Github - hope I did it properly! (very nervous about this..)
Thank you everyone for help, really appreciated!
@vivacelix
edited...
it seems as if
https://github.com/vanilla/vanilla/blob/2.1/applications/vanilla/models/class.categorymodel.php#L147
would be a reasonable mod, if you want to suggest to github.
it should change most things - not the dashboard categories - which you probably wouldn't wnat to change anyway.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
@vivacelix
see if the above works for you.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
@peregrine
OMG! I was about to report on the result of my modifications and here it is, far more elegant and manageable solution! With your previous advice I did achieve what I wanted but ended up modifying 14 core files - I was starting to see what everyone was warning about (haha).
I reverted all of that messy stuff and tried the one-line solution, it works beautifully! Unbelievable. Expert is expert for a reason!
I added the suggestion for the mod in the same Github ticket I just created.
Thanks for a touch of genius. You rock!!