4

I'm working on a multilingual site. I'm Italian and, for some reasons, I would like to use strings in Italian in code (PHP and Twig), not in English.

I've tried this code in a preprocess function.

$variables['test'] = t('Questa stringa è in italiano', [], ['langcode' => 'it', 'context' => 'my_context']);

If I go to admin/config/regional/translate and I look for this string, it's in English, and I have to translate it in Italian.

Is there a way to have Italian as "default language" in code?

0

1 Answer 1

5

There isn’t, it’s hard-coded to require English. The parameters for TranslatableMarkup::__construct (which is what t() returns) confirm:

string $string: A string containing the English text to translate.

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.