I'm really happy that this is brought up.
We have a similar issue in ContentTranslation, where we have to say things like "Translate this article from __________" (
https://phabricator.wikimedia.org/T105588 ). In English it doesn't look like a problem, because you can simply put a language name in the space and it will be correct, but in Russian and in many other languages every language name will have a different ending according to the Russian grammar. It's not easily predictable if you want to cover all the words in a language, but since the number of language names in the world is fairly limited (in practice - less than one thousand), a few lines of code can resolve it.
I also made a simplistic extension called "TestLanguageNameGrammar" that should help translators see how the different language names appear with the different grammar rules. After some cleanup it hope to get it deployed on
translatewiki.net for the translators' benefit.
Once it's merged it will be possible to do it in all MediaWiki-based software, and similar patches will have to be written for other languages by people who know these languages.
Niklas suggested doing it with less code and more data (see the comments on the patch), but it's generally conceivable.
Erik, until we have a nice solution (hopefully soon, once I get that patch merged), please
1. just take the translated names from CLDR
2. create a bug similar to
https://phabricator.wikimedia.org/T105588 for your project, and list the relevant message there
For names of projects like "Wikipedia", "Wikisource", etc., you should use the WikimediaMessages extension. It can also be used to write grammar rules for project names if needed (see the file WikimediaGrammarForms.php there; it is maintained according to community feedback and usually shouldn't directly bother extension developers very much, but it's useful to be familiar with it).