FusionAuth / fusionauth-issues

FusionAuth issue submission project
https://fusionauth.io
91 stars 12 forks source link

Missing default translations keys for theme API #825

Open soullivaneuh opened 4 years ago

soullivaneuh commented 4 years ago

Missing default translations keys for theme API

Description

In order to automate our FusionAuth setup, I have a script that download your default translations files, change some keys and push them trough the API.

I currently have this error:

http: warning: HTTP 400 
{"fieldErrors":{"theme.defaultMessages":[{"code":"[invalid]theme.defaultMessages","message":"You must specify all of the required keys in the [theme.defaultMessages] property. It is missing these keys: [ExternalAuthenticationException]InvalidIdentityProviderId, [WebhookTransactionException], [ExternalAuthenticationException]MissingUser"}]}}

I never changed those keys, and they are indeed not present on the related version translations: https://github.com/FusionAuth/fusionauth-localization/blob/1.18.7/theme/messages.properties

To be sure, I remove my override hack and directly put the official file content: Same thing.

I "solved" my problem by adding those key to my override file:

[ExternalAuthenticationException]InvalidIdentityProviderId=InvalidIdentityProviderId
[ExternalAuthenticationException]MissingUser=MissingUser
[WebhookTransactionException]=WebhookTransactionException

But I don't know what to put in because such references do not exist on your repo.

Affects versions

Not working with v1.18.7.

Working with 1.17.5.

Steps to reproduce

Update the theme translation message trough PATCH /api/theme/{theme_id} resource.

Expected behavior

Update done without any error and without having to add those keys,

Additional context

My theme update script part:

echo "Theme update."
oauth2_templates=""
for oauth2_template_path in templates/oauth2/*; do
    field_name="oauth2$(basename "$oauth2_template_path" |
        cut -d . -f1 |
        awk 'BEGIN{FS="";RS="-";ORS=""} {$0=toupper(substr($0,1,1)) substr($0,2)} 1')
    "
    field_layout=$(jq -aRs . <(cat "$oauth2_template_path"))
    oauth2_templates="${oauth2_templates} | .templates.${field_name} = ${field_layout}"
done
ftp_helpers=$(jq -aRs . <(cat templates/_helpers.ftl))
messages=$(jq -aRs . <(cat locales/messages.properties))
messages_fr=$(jq -aRs . <(cat locales/messages_fr.properties))
jq ".templates.helpers = ${ftp_helpers} ${oauth2_templates} | .defaultMessages = ${messages} | .localizedMessages.fr = ${messages_fr}" \
    theme.json >generated.json
http --check-status --ignore-stdin PATCH "${host_app}"/api/theme/"${theme_id}" \
    "${header_auth}" "${header_json}" \
    theme:=@generated.json

Note: messages.properties and messages_fr.properties are a merge of your official file and my custom keys.

robotdan commented 4 years ago

This is currently working as designed. We have discussed just adding new values to existing themes but we decided against that because we thought it may be a bad idea to silently add new messages to your theme that you don't have a chance to localize.

If you use the UI to update the theme you will be shown a warning and be prompted to add the missing keys automatically. When using the API it is manual as you are doing already.

We could think about adding a new Theme API parameter that would tell FusionAuth to just add any missing values from the default theme w/out a validation error. This would allow the API to work as you would like.

soullivaneuh commented 4 years ago

We have discussed just adding new values to existing themes but we decided against that because we thought it may be a bad idea to silently add new messages to your theme that you don't have a chance to localize.

I understand this part, but because of that, I just have translations key and I don't really know what to put in it.

Having a default value is better and I don't think so much people change what you defined. After all, there is no many ways to translate a sentence. :wink:

If I want to get the default values, what should I do?

robotdan commented 4 years ago

If you use the UI to update the theme you will be shown a warning and be prompted to add the missing keys automatically. When using the API it is manual as you are doing already.

This will be the easiest.

If you want to do it programmatically, you could retrieve the default theme, and parse out the missing keys to get the default english version.

soullivaneuh commented 4 years ago

you could retrieve the default theme, and parse out the missing keys to get the default english version.

This is the issue here. As said on my first comment, I can't retrieve the default missing keys:

I never changed those keys, and they are indeed not present on the related version translations: https://github.com/FusionAuth/fusionauth-localization/blob/1.18.7/theme/messages.properties

robotdan commented 4 years ago

Yes. Good point.

We need to figure how to best solve this, probably one of two options, or both:

  1. The validation API response should include the missing keys and default translations so you can consume this error programmatically and update the theme.
  2. The values can be defaulted through a configuration option or otherwise.
soullivaneuh commented 4 years ago

Thanks!

The default way, as its done for the other keys looks better to me.

soullivaneuh commented 3 years ago

FYI, updating to 1.27.2 comes with additional required keys:

{description}recovery-codes-1
{description}recovery-codes-2
email-verification-required-send-another
[EmailVerificationEmailUpdated]
email-verification-required-title
[cannotSend]method
{description}email-verification-required
[ExternalAuthenticationException]SAMLIdPInitiatedIssuerVerificationFailed
[RegistrationVerificationSent]
{description}registration-verification-required-non-interactive
[moderationRejected]registration.username
{description}registration-verification-required
[ExternalAuthenticationException]SAMLIdPInitiatedResponseSolicited
registration-verification-required-title
registration-verification-required-send-another
{description}email-verification-required-non-interactive
{description}email-verification-required-change-email
[EmailVerificationSent]

But it's even worst for that case because I can find any of those keys on the default localization file: https://github.com/FusionAuth/fusionauth-localization/blob/master/theme/messages.properties.

However, I can find some on the polish translation.

A bit help on that would be greatly appreciated. :slightly_smiling_face:

mooreds commented 3 years ago

@soullivaneuh Thanks! While this doesn't address the original issue, I did just push an updated properties file to https://github.com/FusionAuth/fusionauth-localization/blob/master/theme/messages.properties with all the required keys in it.

We're working on a solution to automate this process, but appreciate your letting us know about the issue with 1.27.2. Sorry about that.

soullivaneuh commented 3 years ago

The following key is missing on v1.28.1: https://github.com/FusionAuth/fusionauth-localization/blob/4b15d67b2eda6202cb44b972a737e88472ebeffb/theme/messages.properties#L93

soullivaneuh commented 3 years ago

Another three required translations on v1.29.0:

pending-device-links=Continue to complete your link to %s and %s.
pending-links-login-to-complete=Login to complete your link to %s and %s.
pending-links-register-to-complete=Register to complete your link to %s and %s.