# Automatically add a space before the emoji if the user is typing Chinese and uses emoji picker

**URL:** <https://meta.discourse.org/t/automatically-add-a-space-before-the-emoji-if-the-user-is-typing-chinese-and-uses-emoji-picker/83285>\
**Category:** Feature\
**Created:** [2018年三月19日 08:24 UTC](https://meta.discourse.org/t/automatically-add-a-space-before-the-emoji-if-the-user-is-typing-chinese-and-uses-emoji-picker/83285 "2018-03-19T08:24:02Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![snakeninny](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/snakeninny/32/115522_2.png) [@snakeninny](https://meta.discourse.org/u/snakeninny)\
**Post date:** [2018年三月19日 08:24 UTC](https://meta.discourse.org/t/automatically-add-a-space-before-the-emoji-if-the-user-is-typing-chinese-and-uses-emoji-picker/83285/1 "2018-03-19T08:24:03Z")

</div>

Hi Discourse team:

I have been using Discourse for 4 years and love the modern design and quick update. Thank you!

Recently I have noticed some issues in my [forum](http://iosre.com), that in China, we seldom use spaces like you do in English, so basically every emoji from emoji picker is screwed like this:

呵呵:thinking:

Which is annoying and confuses most Chinese users. Can you think of a way to improve the Chinese user experience?

Thank you!

Yinglu

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [2018年三月20日 00:06 UTC](https://meta.discourse.org/t/automatically-add-a-space-before-the-emoji-if-the-user-is-typing-chinese-and-uses-emoji-picker/83285/2 "2018-03-20T00:06:12Z")

</div>

Any ideas @j.jaffeux?

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2018年三月20日 01:46 UTC](https://meta.discourse.org/t/automatically-add-a-space-before-the-emoji-if-the-user-is-typing-chinese-and-uses-emoji-picker/83285/4 "2018-03-20T01:46:32Z")

</div>

We half fixed this with:

[https://github.com/discourse/discourse/commit/d2a7a4916abecea389c99ae84de3bd40517b00d9](https://github.com/discourse/discourse/commit/d2a7a4916abecea389c99ae84de3bd40517b00d9)

But what we need to do is match the implementation here:

[https://github.com/discourse/discourse/blob/master/app/assets/javascripts/pretty-text/engines/discourse-markdown/emoji.js.es6#L154-L156](https://github.com/discourse/discourse/blob/master/app/assets/javascripts/pretty-text/engines/discourse-markdown/emoji.js.es6#L154-L156)

Which is checking for `isSpace` or `isPunctChar`.

---

<div class="post-metadata">

**Author:** ![snakeninny](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/snakeninny/32/115522_2.png) [@snakeninny](https://meta.discourse.org/u/snakeninny)\
**Post date:** [2018年七月10日 08:24 UTC](https://meta.discourse.org/t/automatically-add-a-space-before-the-emoji-if-the-user-is-typing-chinese-and-uses-emoji-picker/83285/5 "2018-07-10T08:24:47Z")

</div>

Any progress? Got complaints from my users again today ;(

---

<div class="post-metadata">

**Author:** ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)\
**Post date:** [2018年七月10日 10:15 UTC](https://meta.discourse.org/t/automatically-add-a-space-before-the-emoji-if-the-user-is-typing-chinese-and-uses-emoji-picker/83285/6 "2018-07-10T10:15:21Z")

</div>

You can do this much simpler by always putting a space before the emoji code when selected from the picker.

You can also skip this space if the character immediately before is space.

---

<div class="post-metadata">

**Author:** ![snakeninny](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/snakeninny/32/115522_2.png) [@snakeninny](https://meta.discourse.org/u/snakeninny)\
**Post date:** [2018年七月10日 11:42 UTC](https://meta.discourse.org/t/automatically-add-a-space-before-the-emoji-if-the-user-is-typing-chinese-and-uses-emoji-picker/83285/7 "2018-07-10T11:42:18Z")

</div>

Do you mean doing this manually or programmatically?

---

<div class="post-metadata">

**Author:** ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)\
**Post date:** [2018年七月10日 14:24 UTC](https://meta.discourse.org/t/automatically-add-a-space-before-the-emoji-if-the-user-is-typing-chinese-and-uses-emoji-picker/83285/8 "2018-07-10T14:24:18Z")

</div>

That will need Discourse core to be modified. Probably somebody can write a simple plugin to do this..

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2018年七月11日 01:19 UTC](https://meta.discourse.org/t/automatically-add-a-space-before-the-emoji-if-the-user-is-typing-chinese-and-uses-emoji-picker/83285/9 "2018-07-11T01:19:34Z")

</div>

We have a few options here:

1. Allow `呵:t_rex:` so `:t_rex:` is an emoji. The problem though is that it is very expensive to detect Chinese per [https://github.com/alsotang/is-chinese/blob/master/ischinese.js](https://github.com/alsotang/is-chinese/blob/master/ischinese.js) so this would add a bunch of extra slowness to the MD engine.

2. Fix it so autocomplete behaves consistently with the way the engine interprets it. Meaning `呵:t` **should not** pop open an emoji window.

3. @schungx suggestion where after autocomplete is done we insert a space prior to emoji if needed.

4. Add a “special mode” into Markdown where it requires no special punctuation between emoji and then `a:t_rex:a` would render a 🦖 a.

I feel like the best way forward here is (2) and (4) combined. So:

- Out-of-the-box autocomplete is not doing any funny business where it pretends to add an emoji and does not

- In Chinese forums where words are just joined we would set `SiteSetting.require_punct_before_emoji = false` (and have autocomplete respect this)

@misaka4e21 / @tgxworld what are your thoughts here?

---

<div class="post-metadata">

**Author:** ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)\
**Post date:** [2018年七月11日 01:26 UTC](https://meta.discourse.org/t/automatically-add-a-space-before-the-emoji-if-the-user-is-typing-chinese-and-uses-emoji-picker/83285/10 "2018-07-11T01:26:39Z")

</div>

Yea I think a locale based site setting is best way to go here.

---

<div class="post-metadata">

**Author:** ![misaka4e21](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@misaka4e21](https://meta.discourse.org/u/misaka4e21)\
**Post date:** [2018年七月11日 06:49 UTC](https://meta.discourse.org/t/automatically-add-a-space-before-the-emoji-if-the-user-is-typing-chinese-and-uses-emoji-picker/83285/11 "2018-07-11T06:49:59Z")

</div>

There are two problems:

- (a) If an emoji are chosen from the emoji picker, it will lack for a space before the first colon `:`, not only in Chinese posts, but in English posts as well. Users will get a not rendered a:smile: (`a:smile:`) if they input `a` and then select 😄 (`:smile:`) from the emoji picker.
- (b) A colon `:` after a Latin character won’t cause auto-completion, yet a colon after a CJK Unihan character will. It could be solved exactly by (2).

To solve (a), (3) should be implemented in the emoji picker, not / not just in auto-completion.

(1) and (4) are in different logic.  
To check if a character is in Chinese or not, we could try:

> <https://github.com/zh99998/discourse-username-localization/blob/master/assets/javascripts/discourse/pre-initializers/override-username-match.js.es6#L18>

Though I don’t know whether the regular expression above will provide higher performance.

---

<div class="post-metadata">

**Author:** ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)\
**Post date:** [2018年七月11日 07:48 UTC](https://meta.discourse.org/t/automatically-add-a-space-before-the-emoji-if-the-user-is-typing-chinese-and-uses-emoji-picker/83285/12 "2018-07-11T07:48:20Z")

</div>

I remember going down the regular expression route in the past but that means we carry this giant regexp everywhere we go. For chinese forums, we can just have a site setting that does not require a space before `:` to render emojis.

---

<div class="post-metadata">

**Author:** ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)\
**Post date:** [2019年四月30日 15:52 UTC](https://meta.discourse.org/t/automatically-add-a-space-before-the-emoji-if-the-user-is-typing-chinese-and-uses-emoji-picker/83285/14 "2019-04-30T15:52:09Z")

</div>

@venarius is [UX: Added leading whitespace to emoji picker & inline translation for… by venarius · Pull Request #7429 · discourse/discourse · GitHub](https://github.com/discourse/discourse/pull/7429) going to fix this ?

---

<div class="post-metadata">

**Author:** ![venarius](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/venarius/32/133142_2.png) [@venarius](https://meta.discourse.org/u/venarius)\
**Post date:** [2019年四月30日 16:46 UTC](https://meta.discourse.org/t/automatically-add-a-space-before-the-emoji-if-the-user-is-typing-chinese-and-uses-emoji-picker/83285/15 "2019-04-30T16:46:59Z")

</div>

Yes, this will insert a space before an emoji if there isn’t any.

---

<div class="post-metadata">

**Author:** ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)\
**Post date:** [2019年四月30日 16:58 UTC](https://meta.discourse.org/t/automatically-add-a-space-before-the-emoji-if-the-user-is-typing-chinese-and-uses-emoji-picker/83285/16 "2019-04-30T16:58:57Z")

</div>


