Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Spanish translations in the UI #66

Merged
merged 3 commits into from
Nov 16, 2023
Merged

Use Spanish translations in the UI #66

merged 3 commits into from
Nov 16, 2023

Conversation

oyamauchi
Copy link
Member

@oyamauchi oyamauchi commented Nov 14, 2023

Description

Finally we're here: you can just set lang="es" on the calculator
element (or any ancestor element!) and it'll be in Spanish.

Getting the strings out of the XLIFF file and into code requires
running lit-localize build. Rather than making people do that
manually, I wrote a Parcel resolver that runs the command behind the
scenes. Overengineered? Maybe! But I learned a bunch about Parcel!

Note about switching lang dynamically. Apart from the problem I
noted in the comment on the lang attribute (text that came back
from the API will not change language until the next API fetch),
there's another problem, with the Shoelace select elements: the text
shown in them won't change until you make a new selection in the
element. I think it may be related to
this; in any
case, once all the immediate i18n work is wrapped up I may try to
isolate the issue and file an issue with them if it's not the same
bug. With this bug, dynamically setting the attribute on page load
will leave a couple of untranslated strings, and I think that's a use
case we do want to support.

Test Plan

Add a lang="es" attribute to the main element in
rhode-island.html, and make sure the UI shows up in Spanish. Query
for incentives; make sure the program names of federal incentives show
up in Spanish. (Those are the only thing localized on the backend
right now.)

Copy link

vercel bot commented Nov 14, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
embed-rewiringamerica-org ✅ Ready (Inspect) Visit Preview Nov 16, 2023 6:24pm

@RandomEtc
Copy link
Member

Overengineered? Maybe! But I learned a bunch about Parcel!

❤️

@RandomEtc
Copy link
Member

This is great! I'm wondering if the language= attribute isn't set should we be trying to pick it up from the host page's html lang= attribute?

@oyamauchi
Copy link
Member Author

Hmm the Cypress runs sometimes fail (they time out waiting for the Parcel build to complete), but I'm only seeing this on CI. Will keep looking into it.

## Description

Finally we're here: you can just set `language="es"` on the calculator
element and it'll be in Spanish.

Getting the strings out of the XLIFF file and into code requires
running `lit-localize build`. Rather than making people do that
manually, I wrote a Parcel resolver that runs the command behind the
scenes. Overengineered? Maybe! But I learned a bunch about Parcel!

Note about switching `language` dynamically. Apart from the problem I
noted in the comment on the `language` attribute (text that came back
from the API will not change language until the next API fetch),
there's another problem, with the Shoelace select elements: the text
shown in them won't change until you make a new selection in the
element. I _think_ it may be related to
[this](shoelace-style/shoelace#1570); in any
case, once all the immediate i18n work is wrapped up I may try to
isolate the issue and file an issue with them if it's not the same
bug. With this bug, dynamically setting the attribute _on page load_
will leave a couple of untranslated strings, and I think that's a use
case we do want to support.

## Test Plan

Add a `language="es"` attribute to the main element in
`rhode-island.html`, and make sure the UI shows up in Spanish. Query
for incentives; make sure the program names of federal incentives show
up in Spanish. (Those are the only thing localized on the backend
right now.)
I think the generated files being modified by `lit-localize build` was
causing Parcel to rebuild in an infinite loop. There seems to be no
real way to exclude files from Parcel's watcher in `serve` mode, so
I'm doing so in a very hacky way: putting the generated strings files
in Parcel's cache directory.
@oyamauchi oyamauchi merged commit 9a8f240 into main Nov 16, 2023
3 checks passed
@oyamauchi oyamauchi deleted the owen.setlocale branch November 16, 2023 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants