BiologicalRecordsCentre / ABLE

Assessing ButterfLies in Europe project repository
2 stars 3 forks source link

Enable translation of fields on the user account page #475

Open JimBacon opened 2 years ago

JimBacon commented 2 years ago

When editing account details, custom field labels, help text, and choices are only in English. There is no option to provide translation.

image

JimBacon commented 2 years ago

To enable the translation of field settings (and much more), I have enabled the Multilingual:Configuration Translation and the Translation Management:Config Entity Source modules. Only administrators currently have permissions for it.

Now if you go to Translation > Sources there are many more options in the 'Choose source' drop down list. Choose 'Config Entity: Field' and you will see e.g. 'First name' and 'Last name' in the list. I'm not clear if sending these for translation will only include the label.

If, instead, you go to Configuration > People > Account settings > Manage fields, find e.g. 'First name' in the list and select 'Translate'' from the list of Operations, and click an Add button then it clearly offers translation of both label and help text.

JimBacon commented 2 years ago

If you try to translate a user field which has a Field Type of list, an error occurs.

A warning is generated like

The configuration objects have different language codes so they cannot be translated:
    field.field.user.user.field_default_species_view: en
    field.storage.user.field_default_species_view: und

and the log contains the message

Drupal\config_translation\Exception\ConfigMapperLanguageException: 
    A config mapper can only contain configuration for a single language. 
    in Drupal\config_translation\ConfigNamesMapper->getLangcode() 
    (line 404 of /code/web/core/modules/config_translation/src/ConfigNamesMapper.php).

There is a related issue, https://www.drupal.org/project/drupal/issues/2909935

JimBacon commented 2 years ago

To fix the above issue I used Terminus to run Drush commands to modify the language codes as follows:

terminus drush brc-ebms.live cset field.storage.user.field_location_expertise langcode en
terminus drush brc-ebms.live cset field.storage.user.field_default_species_view langcode en
terminus drush brc-ebms.live cset field.storage.user.field_location langcode en
terminus drush brc-ebms.live cset field.storage.user.field_taxon_groups_expertise langcode en
terminus drush brc-ebms.live cset field.storage.user.field_surveys_expertise langcode en
terminus drush brc-ebms.live cset field.storage.user.field_u16 langcode en

@CrisSevilleja it should now be possible to add translations related to account settings. Could you try it out?

CrisSevilleja commented 2 years ago

@JimBacon I added the translations of 'First name' and 'Last name' into Spanish through the path you described (Configuration > People > Account settings > Manage fields, find e.g. 'First name'). Everything worked well and I didn't get any warning message.

I still don't see those translations on the website, maybe it takes time to appear.

JimBacon commented 2 years ago

You just needed to Flush all caches. image

CrisSevilleja commented 2 years ago

now it works ;)

So, now to go further with the rest of the languages, I need to do it that way, directly including the translation there and not through Transifex, right? @JimBacon

JimBacon commented 2 years ago

What happens if you check the boxes against the languages you want to translate and then click the Request Translation button? image

CrisSevilleja commented 2 years ago

I managed to send the requested translations for the three languages.

2022-09-01_10h57_39
JimBacon commented 2 years ago

It looks like it is mostly working. There are 6 strings to translate for this field: The label, help text, and four options. The three requests with 6 strings and 90 words show in the list of translation jobs. image

However, Transifex lists 5 strings and 86 words image

It has missed the option 'The full taxa list' image

We will have to see whether this is a repeatable problem or just a glitch on this occasion.

I don't understand how to see on Transifex whether the request is for all languages or just the three you selected.

CrisSevilleja commented 2 years ago

you can check it on the language to translate

2022-09-01_12h12_18

However, I don't know if Hungarian, for example, was not requested, if the translation is given that would be applied on the website....