wri / gfw

Global Forest Watch: An online, global, near-real time forest monitoring tool
https://www.globalforestwatch.org
MIT License
273 stars 93 forks source link

[FLAG-1035] Fix variables in the integrated deforestation alerts widget for translations to work properly #4831

Closed SARodrigues closed 2 months ago

SARodrigues commented 3 months ago

Overview

This PR aims to address a few issues with the integration deforestation alerts widget's translations, as well as a few others. This implementation focuses mainly on two aspects:

 

Date localization

A similar setup to the one used for localizing dates in the blog (see here)[https://github.com/wri/gfw-blog/pull/155] was implemented. It makes use of date-fns, which already exists in the application.

An util/helper was created that contains:

I did notice that many widget use moment.js for date calculations, I did not change this. The change is only for localization of the dates.

 

Interpolation and Transifex

This was a bit more confusing but from what I gathered, translation with variable interpolation works correctly for sentences defined in a widget's index.js, due to the use of <DynamicSentence /> (we may need to deep dive into this in the future).

However, I've noticed some widgets do have extra text additions specified in a widget's selectors.js's parseSentence. In this case, when these sentences also include an interpolation, we end up with an interpolation inside another interpolation, so this second nested level doesn't get automatically processed.

I did find, however, that we already have an translateText in utils/lang to address scenarios where we need to have the strings translated w/ interpolation of values; it is used in many places of the app. I tried to find as many widgets as I could that needed this change and added it to them.

I do not currently have a Transifex account, but I am making an educated guess (from what I've learned from other parts of the application, and the next section below) that these smaller strings are now being sent to transifex; they will need to be translated.

 

Integrated deforestation alerts dropdown

Transifex already has the translations for the sentences that weren't being translated (as the sub-items in the dropdown were being translated), so adding the translateText to the main button caused them to work again.

Tracking

FLAG-1035