discourse/discourse — pull request #677 by kubabrecka (2013-04-08 21:06:48+00:00)
Title: move i18n of UserActions to JS-side and make sentences translatable

This is a pull request to make translations of user actions ("user1 mentioned user2"). Basically, the the whole thing is a way to have whole sentences in client.xx.yml:

{{user}} posted the topic
You replied to {{post_number}}

I also moved the creation of the sentence to the client side, and I there is one more thing: Since we want the "You" to be clickable, we have to either to split the sentence into parts (which makes it untranslatable again) or mark the parts of the string somehow. I chose this approach:

user_replied_to_topic: "

{{user}}

replied to the topic"
you_replied_to_topic: "

You

replied to the topic"
user_mentioned_user: "{{user}} mentioned {{another_user}}"
posted_by_user: "Posted by

{{user}}

"

Marking the various parts with meta-tags e.g. `...`, which get replaced in JS by a link instead.

Now if you look at the code, maybe you'll think that I replaced a neatly parametrized code by a giant switch, and you're right. But currently, Discourse assembles a sentence by concatenation ("subject" + "verb" + "object"), which makes it untranslatable. Also, we have to distinguish situations when subject is 1st person and when it is 2nd person (you), these usually translate differently.