1

I am developing my custom module. I have the html template look like this

<p>
  This is a <strong>text that I need to translate</strong>
</p>
<p>Read more: <a href="" target="_blank" rel="noopener noreferrer">google.com</a></p>

How can I translate these nested texts? I know how to use i18n to translate but I don't know how to translate the text in <p> tag that has <strong> tag in the middle

I used this but not work

  <p >{{trans "This is a"}} <strong>{{trans "text that I need to translate."}}</strong></p>

I can do this and it works but I really don't like the extra span tag

 <p ><span data-bind="i18n: 'This is a '"/><strong data-bind="i18n: 'text that I need to translate.'"/></p>

NOTE: My file is the js component template so it's HTML. It is not phtml file

5
  • {{trans "A nice quote"}} and you might need a translation csv in your theme or something, this in email templates for example, in code you can try the function __('A nice quote'), I'm not good in defining translations myself but hope it helps or lead to something :D
    – Rui Silva
    Aug 5, 2020 at 9:07
  • Any tutorials/blogs/...that you recommend?
    –  coinhndp
    Aug 5, 2020 at 10:38
  • What do you want to translate? Text in email templates? In code? Translate the whole website to another language?
    – Rui Silva
    Aug 5, 2020 at 11:43
  • That's the text in my custom module. I know how to use i18n to translate but I don't know how to translate the text in <p> tag that has strong tag in the middle
    –  coinhndp
    Aug 5, 2020 at 11:58
  • Try to use __() instead of the {{trans }} might be easier
    – Rui Silva
    Aug 5, 2020 at 12:13

1 Answer 1

1

Try it like this

first create a custom module using this link https://www.mageplaza.com/magento-2-module-development/

Now create Below directory

Vendor/Module/i18n/en_US.csv

Now in open en_US.csv in notepad and translate like below example

"Position","Featured"

here am changing Position with Featured

that's it you are done

1
  • Hi, I updated my question
    –  coinhndp
    Aug 5, 2020 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.