Bcat
(Bcat)
May 19, 2020, 10:49am
1
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
https://github.com/bcat95/discourse-topic-share/blob/0a24b3fc965748f715be7f04923027028c943df4/common/head_tag.html#L33
I try: I18n.t(themePrefix("my_translation_key"))
Johani
(Joe)
May 19, 2020, 11:10am
2
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
I18n.t("TRANSLATION_KEY")
For example this
h('span', 'Chia sẻ qua Facebook')
becomes
h("span", I18n.t("share.facebook"))
6 Likes
Without this line, the i18n works fine. Otherwise, error occurs: “Could not find module I18n”.
Johani
(Joe)
June 3, 2020, 7:14pm
5
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
3 Likes
Bcat
(Bcat)
June 4, 2020, 2:30am
6
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;
`
Johani
(Joe)
June 4, 2020, 2:32am
7
I’m not sure I understand. Can you please clarify what you mean here?
Bcat
(Bcat)
June 4, 2020, 2:34am
8
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.
Johani
(Joe)
June 4, 2020, 2:39am
9
Thanks for clarifying
Yeah updating 300+ files manually would take a lot of time. The files were updated with a script that Mark created.
3 Likes
system
(system)
Closed
July 4, 2020, 2:39am
10
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.