0

I want to write some JavaScript code for my project. I need to use Drupal.t(), but it seems that Drupal.t() only accepts English, and I don't want to write my JavaScript in English.

Is there any way to inform Drupal.t() that my string is not in English, just like t() that let you specify the language code.

| improve this question | | | | |
0

The string that you pass as first argument to Drupal.t() (as it happens with t()) needs to be in English, since the function translates a string from English to another language.

Differently from t(), which allows you to pass the language code for the language you want to translate the string, Drupal.t() doesn't have that possibility. Its arguments are the following:

  • str
    A string containing the English string to translate.
  • args
    An object of replacements pairs to make after translation. Incidence of any key in this array are replaced with the corresponding value. See Drupal.formatString().
  • options
    • 'context' (defaults to the empty context): The context the source string belongs to.

Reference

| improve this answer | | | | |
0

Nope, not really. Drupal is built from ground up in English and that's the way you need to build your modules too. Some parts of the code tries to enable you provide default texts in another languages, but it's a disaster if you decide to change default language later.

It is possible to built functionality like you need in a custom module, it is even possible someone did, but I don't know of any reliable solution.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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