Open almchung opened 3 years ago
Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, be sure to follow the issue template if you haven't already.
This plan looks great! Some comments:
- (b) The Web Editor react app’s language state is updated when language selection event happens (e.g. the dropdown menu UI), as seen in components/Nav.jsx/handleLangSelection(). I’m not sure whether we'll need to reload the sketch iframe/update language here.
You will need to! The easiest way may be to reload the entire sketch, which is probably okay because users are likely not changing the language often.
- Web editor: Change language within the Sketch iFrame When
EmbedFrame
finally receives the language option, I have a hacky plan to add a scriptp5._setTranslatorLanguage ({{langugage code}});
to the iframe HTML. Maybe we can dynamically generatedefaultHTML
based on the language option? If you know a more elegant way, I'd love to learn it!
I'm going to have to think about the right way to do this. One easy way would be to pass the language to the sketch (here is a part of EmbedFrame that is passing variables to the sketch). Then, in previewEntry.js, you have access to the p5 instance (example that accesses the global p5 variable).
Some issues with this approach are:
Another option I've thought about is the editor creating a "config.js" file that would add this option automatically (and in the future, would also support configuring accessibility outputs as well), but it's unclear how to present this file to the user (can they edit it? how do you prevent them from editing it?)
Thanks for writing this up @almchung! Looks good from my side. :)
That sounds right to me! And the place you chose looks good to me too. You might also need a p5._availableTranslatorLanguages
to query for the settings page to know which translations are supported in the sketch's version of p5, but maybe we could just keep the most recent release's supported languages list in the editor? i think i18next
will just fallback to english if the translation language asked for doesn't exist in the sketch's loaded translations and that's behavior we can customize. (this is kind of getting into point 2b).
These are all great suggestions! Thank you, @catarak and @outofambit!! To get things moving, I'll add a checklist here shortly.
Also @outofambit, I'll open a new issue on the p5.js repo with a summary of this issue and the checklist.
p5._availableTranslatorLanguages
startSketch()
payloadcomponents/Nav.jsx/handleLangSelection()
to reload the sketch iframemodules/Preview/previewIndex.jsx
to handle the language optionp5._setLanguage()
method at EmbedFrame
)p5._setLanguage()
method and implement the final versionThis project will be on hold until early this summer when the development direction for the FES becomes clearer. Thank you!
Nature of issue?
Feature enhancement details:
This issue proposes an integration plan between the web editor and the Friendly Error System (FES).
The current web editor successfully displays FES messages in the default language. It would be even more helpful if the language of FES automatically matches with the detected or selected language in the web editor!
To integrate FES with the web editor, I’m thinking of following these steps:
p5js: Expose the language switching function This mainly means to extend
setTranslatorLanguage()
from our i18n module [LINK].p5._setTranslatorLanguage()
can be a way to do this [LINK]. (Not sure whether this is the best place for it.)Web editor: Identify where the language option needs to be updated (a) We’ll need to add the language option to where the sketch (in iframe) begins to run, such as the
startSketch()
payload inmodules/IDE/actions/ide.js
. Here we'll pass the locale detected by the Web Editor app. (b) The Web Editor react app’slanguage
state is updated when language selection event happens (e.g. the dropdown menu UI), as seen incomponents/Nav.jsx/handleLangSelection()
. I’m not sure whether we'll need to reload the sketch iframe/update language here. (c) I wonder if I’m missing any other cases?Web editor: Handle messages with the language option We’ll need to edit
modules/Preview/previewIndex.jsx
to handle the posted request and relay the language option toEmbedFrame
.Web editor: Change language within the Sketch iFrame When
EmbedFrame
finally receives the language option, I have a hacky plan to add a scriptp5._setTranslatorLanguage ({{langugage code}});
to the iframe HTML. Maybe we can dynamically generatedefaultHTML
based on the language option? If you know a more elegant way, I'd love to learn it!@catarak and @outofambit, please feel free to comment if you have feedback on any of these steps.
Thank you! :)