I have an address field from which I’m getting a country code and then, using the address.country_repository
service, checking the country’s name.
$full_country_list = Drupal::service('address.country_repository')->getList(); $country_code = $user->field_nationality->first()->get("country_code")->getValue(); $result['nationality'] = t($full_country_list[$country_code], [], ['langcode'=>$user->get('langcode')->value]);
This repository returns a list with the country names translated in Drupal’s default language (in my case, portuguese), but I’m trying to t()
-function it to translate the string into other languages.
The t()
function doesn’t cut it, even if I pass the langcode
option.
How can I get a translated version of the list so that I don’t have to translate the string with t()
?