Move loading of en locale into Component.js files, use __locales__ for Locale messages, and update tests.#1509
Open
dpvc wants to merge 2 commits into
Open
Move loading of en locale into Component.js files, use __locales__ for Locale messages, and update tests.#1509dpvc wants to merge 2 commits into
en locale into Component.js files, use __locales__ for Locale messages, and update tests.#1509dpvc wants to merge 2 commits into
Conversation
…r Locale messages, and update tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR moves the loading of the
enlocale from the component definitions (using theen.jsfiles incomponents/mjs/...) to their__locales__/Component.tsfiles instead. That means that those building MathJax apps using direct imports of the MathJax modules will get the English error messages loaded automatically, and we don't have to have a message about not having calledLocale.setLocale(). This means the localization isn't a breaking change.A second change is that the localization of the messages in the
Localeobject itself are now in a newts/util/Locale/__locales__directory. This means we don't have to have all the languages' messages in theLocaleobject initially, and since we now load theenmessages automatically, that has the same effect as having them in line. Thelocalefake component is the first one registered, so it will always be loaded first when the locale is changed, so locale messages should be available if they are needed once a locale is changed (if not, the fallback to English will at least give a proper, if unlocalized, message). A copy command for the utility locales is added topackage.jsonto accommodate this, and a newcomponents/mjs/localecomponent is created that only copies the files (like thecomponents/mjs/srecomponent does) is added.The Locale test file is updated to get coverage for some changes in
Locale.tsand the clean up registered components or messages after tests that set them.The
ts/util/Locale.tsfile was modified to define aCOMPONENTlike the ones from__locales__/Component.ts, but we can't useComponent.tsfile forLocalebecause theLocaleobject has to be defined before we can callLocale.registerLocaleFiles(), like we do on the otherComponent.tsfiles. Instead, we import theen.jsonfile directly and register it in this file afterLocaleis defined. We also changeregisterLocaleFiles()to avoid overwriting a previous registration if there was already one made earlier (e.g., if the ui/menu and a11y/explorer components are loaded separately, both of which register the a11y/aria fake component).The
registerMessages()method now produces an error message if you try to register messages for a component that isn't registered (addressing your review comment in #1494.Finally, I shortened the localization keys, and added the new message to the
en.jsonandde.jsonfiles.I know this looks like a lot of files, but most of them are just deleting the
en.jsfiles fromcomponents/mjs/..., removing the imports of those files from the component definitions, and adding the loading and registering ofento all the__locales__/Component.tsfiles.