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

Basic localization support #1344

Merged
merged 36 commits into from
May 30, 2024

Conversation

Aaron-212
Copy link
Contributor

@Aaron-212 Aaron-212 commented May 8, 2024

Close #1340

Todos

  • add support to plural forms
  • localize strings that are used directly into html elements
  • localize strings that are used directly into html attributes
  • read localization data from different .json files instead of hardcoding it inside .js
  • a switch-language menu
  • changes should be applied without refreshing the page
    current workaround: use location.reload(true) to reload

Copy link

google-cla bot commented May 8, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@Aaron-212
Copy link
Contributor Author

Is there any way to reload the UI without refreshing the whole page?

@justvanrossum
Copy link
Collaborator

Is there any way to reload the UI without refreshing the whole page?

Not really. I'd need to look into editor.js, maybe it should get a method to that effect. The closes thing would be is to call editorController.reloadData(). Hmm, maybe that just works.

Else: what are the downsides of a page reload for what you are doing?

@justvanrossum
Copy link
Collaborator

Random idea (to be considered for later, it may not be that relevant for this initial work): should we maintain the translations as a (google-docs or equivalent) spreadsheet, to make it easier to onboard people who can help with providing/fixing/checking translations?

@justvanrossum
Copy link
Collaborator

Please run pre-commit install if you haven't already, that should help keeping the project's formatting as expected.

@Aaron-212
Copy link
Contributor Author

Aaron-212 commented May 9, 2024

EditorController.reloadData() breaks the whole thing 😂
image
But using location.reload(true) (full reload) also has some issues. Some localization data won't load after refreshing multiple times.
image
But for most times location.reload(true) can do the work.
image


After doing some testing around reloading the web page, I found this issue only appears on Chrome. Safari can load all localization data no matter how you reload. And Chrome sometimes doesn't localize at all, only showing the keys.
image
This is so weird


Just font out that CMD+R reload on Chrome doesn't ignore cached content, and so does location.reload() or location.reload(true).

@Aaron-212
Copy link
Contributor Author

image

Figured out an alternative way to call editorController.reloadData(), but most of the localization are not reloaded.

@Aaron-212
Copy link
Contributor Author

Random idea (to be considered for later, it may not be that relevant for this initial work): should we maintain the translations as a (google-docs or equivalent) spreadsheet, to make it easier to onboard people who can help with providing/fixing/checking translations?

Maybe using professional platforms like Crowdin or Transifex is a better idea. They offer free project hosting for open-source repos.
But integrating them into current workflow is another problem.

@Aaron-212
Copy link
Contributor Author

Rebased
But I still cannot figure out a proper way to use editorController.reloadData()😂
Guess I'll just stick to window.location.reload(true)

@justvanrossum
Copy link
Collaborator

About the json prettier plugin: that's fine as long as we have control about which files it will touch. Like, there are .json files in test-common that I'm not sure I want to be touched. There are .json files inside .fontra folder that should not be touched, but I think they are already ignored.

@Aaron-212
Copy link
Contributor Author

I'm planning to mark this PR as ready, since there're too many files modified. The main editor is almost localized, and for unlocalized dialogs and pop-ups I'll open a second PR after this one's merged.

@Aaron-212 Aaron-212 marked this pull request as ready for review May 26, 2024 07:59
Copy link
Collaborator

@justvanrossum justvanrossum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for this huge amount of work, and for keeping it up to date!

I left some comments.

General question, if I find things that are not yet translated, would you like me to tell you, or are you aware? For example, I found the dialogs that use "_sourcePropertiesRunDialog" to be untranslated.

src/fontra/views/fontinfo/panel-axes.js Show resolved Hide resolved
src/fontra/client/web-components/ui-form.js Show resolved Hide resolved
src/fontra/views/editor/cjk-design-frame.js Show resolved Hide resolved
src/fontra/views/editor/panel-designspace-navigation.js Outdated Show resolved Hide resolved
src/fontra/views/editor/panel-user-settings.js Outdated Show resolved Hide resolved
@justvanrossum
Copy link
Collaborator

Please use pre-commit, you may have to run "pre-commit install" to turn it on for this repo.

I notice in the test fail that it reformats some .json files that are unrelated to this PR. I would prefer them to not be changed. Maybe you can activate the json prettier only for the files you are interested in?

@justvanrossum
Copy link
Collaborator

I see that if a translation is not found, the key is returned.

I'm worried about new things that will be added, which will be in English first. Imagining we may have more translations in the future, I wonder if we should fall back to english if a translation isn't found. Else we'd be forced to always have all new translations ready at the same time, which seems impractical.

@Aaron-212
Copy link
Contributor Author

IMO this isn't a big problem right now, since we can still hardcode the English strings in the source code for new strings. I'll add the fallback strategy in the next PR, so that new strings can use translate(key) directly.

@justvanrossum justvanrossum merged commit 154c1fb into googlefonts:main May 30, 2024
3 checks passed
@justvanrossum
Copy link
Collaborator

Thanks so much!

@Aaron-212 Aaron-212 deleted the localization-support branch May 30, 2024 07:21
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.

Localization support
2 participants