Similar to Robert and Oded's answer, I'd offer the rule of thumb I use when answering questions here and elsewhere:
If a question is asking for a specific method of doing something (normally questions like 'How do I do x in language Y', 'how to use language-specific feature Z' or simply 'A is not working in my code') then a clear answer in the same language is better, especially when accompanied by a sentence or two explaining why your specific approach is a good one (why one library is better than another for the task at hand, or what error you've fixed in the original code)
If a question is asking about an approach, or or an algorithmic nature as Robert noted (e.g. 'What is the best way to do X' etc.) then a general answer is almost always better unless they have specifically requested a code snippet as figuring out how to apply that general advice to their language/situation not only helps them learn and allows them to feel as though they've achieved something themselves (and not been spoon-fed a solution and still not fully understanding it), but they can also apply that knowledge to similar situations - things you don't get from "try this code instead".
Ideally, of course, a good answer would contain enough information explained clearly enough that it actually ticks both boxes by providing an answer that is applicable to the problem that caused the question while being useful to someone facing the same issue in another language, but that can often make the answers much more difficult and longer to come up with. Similarly, there are a number of areas where there is no clear boundary between the two types I've outlined above but that is one of the reasons that we ask our questions t people and not machines - we can tailor our answers to help the asker in different ways.
It may seem like I have stated nothing new, but I have found that spending a moment or two thinking about what the questioner really wants to know (often not exactly what they are asking) helps prevent the questioner sending both of you back to square one with 'Sorry, I still don't understand'.