# How to show site\_texts strings to themes and theme components?

**URL:** https://meta.discourse.org/t/how-to-show-site-texts-strings-to-themes-and-theme-components/151927
**Category:** Support
**Created:** [19 במאי,‏ 2020,‏ 10:49am UTC](https://meta.discourse.org/t/how-to-show-site-texts-strings-to-themes-and-theme-components/151927 "2020-05-19T10:49:08Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Bcat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bcat/32/163148_2.png) [@Bcat](https://meta.discourse.org/u/Bcat)
#### Post date: [19 במאי,‏ 2020,‏ 10:49am UTC](https://meta.discourse.org/t/how-to-show-site-texts-strings-to-themes-and-theme-components/151927/1 "2020-05-19T10:49:08Z")

</div>

I have created Tocic Share but want to use the default **js.share.facebook** example, [but according to this article](https://meta.discourse.org/t/adding-localizable-strings-to-themes-and-theme-components/109867), I wrote it wrong so it doesn’t show.  
Can show me how to display properly instead of adding new words to the topic

> <https://github.com/bcat95/discourse-topic-share/blob/0a24b3fc965748f715be7f04923027028c943df4/common/head_tag.html#L33>

 ![image](https://global.discourse-cdn.com/meta/original/3X/e/e/eeb17c31623690fd3ea518dceea061999eb950a5.png)

I try: `I18n.t(themePrefix("my_translation_key"))`

---

<div class="post-metadata">

### Author: ![Johani](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/johani/32/176920_2.png) [@Johani](https://meta.discourse.org/u/Johani)
#### Post date: [19 במאי,‏ 2020,‏ 11:10am UTC](https://meta.discourse.org/t/how-to-show-site-texts-strings-to-themes-and-theme-components/151927/2 "2020-05-19T11:10:14Z")

</div>

Add this at the top of your component

```javascript
const I18n = require("I18n").default;

```

You can then use something like this when you need to use the default Discourse text

```javascript
I18n.t("TRANSLATION_KEY")

```

For example this

```javascript
h('span', 'Chia sẻ qua Facebook')

```

becomes

```javascript
h("span", I18n.t("share.facebook"))

```

---

<div class="post-metadata">

### Author: ![Bcat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bcat/32/163148_2.png) [@Bcat](https://meta.discourse.org/u/Bcat)
#### Post date: [19 במאי,‏ 2020,‏ 11:54am UTC](https://meta.discourse.org/t/how-to-show-site-texts-strings-to-themes-and-theme-components/151927/3 "2020-05-19T11:54:44Z")

</div>

thank you very much. 😄

---

<div class="post-metadata">

### Author: ![wyudong](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/wyudong/32/180747_2.png) [@wyudong](https://meta.discourse.org/u/wyudong)
#### Post date: [3 ביוני,‏ 2020,‏ 2:59pm UTC](https://meta.discourse.org/t/how-to-show-site-texts-strings-to-themes-and-theme-components/151927/4 "2020-06-03T14:59:26Z")

</div>

> [@Johani](#):
>
> `const I18n = require("I18n").default;`

Without this line, the i18n works fine. Otherwise, error occurs: “Could not find module I18n”.

---

<div class="post-metadata">

### Author: ![Johani](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/johani/32/176920_2.png) [@Johani](https://meta.discourse.org/u/Johani)
#### Post date: [3 ביוני,‏ 2020,‏ 7:14pm UTC](https://meta.discourse.org/t/how-to-show-site-texts-strings-to-themes-and-theme-components/151927/5 "2020-06-03T19:14:11Z")

</div>

That depends on your Discourse version. I18n used to be globally defined so you didn’t need to import it on older Discourse versions.

If your site is on a recent commit like the OP, then you need to import / require it.

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

---

<div class="post-metadata">

### Author: ![Bcat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bcat/32/163148_2.png) [@Bcat](https://meta.discourse.org/u/Bcat)
#### Post date: [4 ביוני,‏ 2020,‏ 2:30am UTC](https://meta.discourse.org/t/how-to-show-site-texts-strings-to-themes-and-theme-components/151927/6 "2020-06-04T02:30:07Z")

</div>

Is it automatic or did you manually change 352 changed files? 🙄

@wyudong I used `h("span", I18n.t("share.facebook"))` No need to add `const I18n = require ("I18n"). default;` `

---

<div class="post-metadata">

### Author: ![Johani](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/johani/32/176920_2.png) [@Johani](https://meta.discourse.org/u/Johani)
#### Post date: [4 ביוני,‏ 2020,‏ 2:32am UTC](https://meta.discourse.org/t/how-to-show-site-texts-strings-to-themes-and-theme-components/151927/7 "2020-06-04T02:32:23Z")

</div>

> [@Bcat](#):
>
> Is it automatic or did you manually change 352 changed files? 🙄

I’m not sure I understand. Can you please clarify what you mean here?

---

<div class="post-metadata">

### Author: ![Bcat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bcat/32/163148_2.png) [@Bcat](https://meta.discourse.org/u/Bcat)
#### Post date: [4 ביוני,‏ 2020,‏ 2:34am UTC](https://meta.discourse.org/t/how-to-show-site-texts-strings-to-themes-and-theme-components/151927/8 "2020-06-04T02:34:56Z")

</div>

I am wondering you have to change each file then commit. Or have it automatically (change multiple files at once)  
This question is not important. If with personal knowledge maybe I will change each file and it takes all day ☹  
GIT, I don’t have much experience.

---

<div class="post-metadata">

### Author: ![Johani](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/johani/32/176920_2.png) [@Johani](https://meta.discourse.org/u/Johani)
#### Post date: [4 ביוני,‏ 2020,‏ 2:39am UTC](https://meta.discourse.org/t/how-to-show-site-texts-strings-to-themes-and-theme-components/151927/9 "2020-06-04T02:39:02Z")

</div>

Thanks for clarifying 👍

Yeah updating 300+ files manually would take a lot of time. The files were updated with a script that Mark created.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [4 ביולי,‏ 2020,‏ 2:39am UTC](https://meta.discourse.org/t/how-to-show-site-texts-strings-to-themes-and-theme-components/151927/10 "2020-07-04T02:39:19Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
