How to show site_texts strings to themes and theme components?

I have created Tocic Share but want to use the default js.share.facebook example, but according to this article, I wrote it wrong so it doesn’t show.
Can show me how to display properly instead of adding new words to the topic

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

Add this at the top of your component

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

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


For example this

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


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

thank you very much. :smile:

1 Like

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

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.


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

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

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

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 :frowning:
GIT, I don’t have much experience.

Thanks for clarifying :+1:

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


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