Add localization for remaining core functions and add tests#1487
Open
dpvc wants to merge 1 commit into
Open
Conversation
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 localizes the files that are part of the
corecomponent, which includes thets/utilfiles and the files ints/core. It also include the messages fromts/output/commoneven though those aren't in the core component, but since there are only a few of them, and thecommoncode is in more than one output component, they are put in core to avoid duplication inoutput/chtmlandoutput/svg.Details
A new
testsuite/src/locale.tsis added that sets up the locales. Because thesetupTexis included in theindex.jsfile in#helpers, and it loadsnode-main, which sets upmathjax.asyncLoadto be a synchronousrequire-based call, that altered some of the Locale test behavior. This file can be used in non-tex tests (like the util tests) to initialize the locale without alteringasyncLoad.In
setupTex.ts, we pre-loadAsyncLoadand informLocalethat it is synchronous so thatLocale.setLocale()will be synchronous (more about this later). That way, we don't have to make thesetupTex()and related functions beasync, which would require changing a bunch of tests that use it. (So we no longer return promises from those.) We move theLocale.setLocale()to before the creation of the MathDocument in order to avoid the message aboutLocalenot being initialized.The
utiltests are modified to load the newsrc/locale.jsfile. Tests are added toLocale.test.tsto test the synchronous loading and the new setup code (described when discussingLocalechanges below). Because thecorecomponent is now being registered whenever a core module is loaded,Locale.setLocale()will try to load acore/__locales__/*.jsonfile, so some tests that use undefined locales end up throwing that error for that. So we trap those errors when we don't care about them, and remove theMathJax(component)prefix from some tests, since the actual component that throws the error may be different (e.g.,MathJax(core)).A few other tests are changed to accommodate changes in the error strings (like
"to', so make the json files easier to deal with).Most of the rest of the changes are the localizations of the messages in various files.
For the
ts/core/MmlNodefiles, themError()function is modified to take a message ID and an array of substitutions as its arguments rather than the message itself. Technically, this is a breaking change, but unless someone has created their own internal MathML node, it should not affect anyone.Finally, the changes to
ts/util/Locale.tsare for two things: to allow for synchronous loading of locale files, when possible, and to avoid a cyclical dependency. For the latter, now thatts/util/AsyncLoad.tshas been localized by importing thecore/__locales__/Component.tsfile (which callsLocale.registerLocaleFiles()), importingAsynchLoadintoLocale.tswould causeLocale.registerLocalFiles()to be called beforeLocaleis set up, causing an error.To avoid this,
Localenow puts off loadingAsynchLoaduntil theLocale.setLocale()call, and usesimport()to do so asynchronously. It checks whethermathjax.asyncIsSynchronousis true, and save that asLocale.syncLoadif it is. ThegetLocaleData()method is modified to usethis.syncLoad()when it is available in order to do the file loading synchronously, so thatLocale.setLocale()is synchronous rather than asynchronous (though it still returns a promise).Note, however, that the first call to
Locale.setLocale()would still be asynchronous in order to wait formathjax.tsandAsyncLoad.tsto load. To really makeLocale.setLocale()completely synchronous, one needs to setLocale.syncLoadby hand beforeLocale.setLocale()is called. That is whysetupTex.tsdoes that for the testsuite, thus allowingsetupTex()and related functions to be synchronous, avoiding the need forawaitandasyncfunctions in the tests that callsetupTex(), as described above.