0

Let's say I have the following code:

define([
    'jquery',
    'mage/translate',
], function (
    $,
    $t
) {
    'use strict';
    return function (str) {
        //Rest of codes to determine output
        return $t(return_string);
    });
}

I have all possible values of return_string on translate file. But it fails to translate at all on frontend. What can I do here to make return_string return translated string?

4
  • Are you using this return_string somewhere? I mean in phtml or html? Aug 24, 2021 at 9:21
  • I use it on html
    – PY Yick
    Aug 25, 2021 at 2:11
  • Did you try translating it in html? Aug 25, 2021 at 4:46
  • I tried with no avail. Anyway, I solved it by inject the translated string in the file. Thanks for your help!
    – PY Yick
    Aug 27, 2021 at 8:37

1 Answer 1

0

I encountered this issue before. The problem is, that the "keys" that you want to translate need to be rendered in a phtml or HTML file first.

I usually do this in a hidden .

1
  • Anyway, I solved it by inject the translated string in the file. Thanks for your help!
    – PY Yick
    Aug 27, 2021 at 8:38

Your Answer

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

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