mnater / Hyphenopoly

Hyphenation for node and Polyfill for client-side hyphenation.
http://mnater.github.io/Hyphenopoly/
MIT License
696 stars 44 forks source link

Is late instantion of a language possible? #170

Closed dimovpetar closed 3 years ago

dimovpetar commented 3 years ago

Hello,

Is it possible to initialize a language only if it's needed? I need to support a lot of languages and I don't want to load all the .wasm files if they won't be used. Also the language can change at any time. Currently I'm using Hyphenators and I'm following the instructions:

  1. Configuration
  2. Load and run Hyphenopoly_Loader

Is it possible to skip the "require" part of the Configuration and add it later?

Best regards, Petar

mnater commented 3 years ago

Hi

This is not implemented, yet. But I see the use case. Would it be OK if Hyphenopoly automatically loads the .wasm file if you request a hyphenator with settings for a specific language that has not been loaded? I think I could implement that in a few days.Looks interesting...

Kind regards, Mathias

dimovpetar commented 3 years ago

Hello @mnater ,

Thanks for the fast response! Yes, loading the .wasm file when the language is requested is exactly what I need. I would still need to use "leftmin", "rightmin", "minWordLength" and the other settings, and also to force the loading of the engine, like "FORCEHYPHENOPOLY" currently does.

Something like:

Hyphenopoly.loadHyphenEngine(lang, langSettings).then(function () { 
    Hyphenopoly.hyphenators[lang] // Promise that resolves with the hypenator or undefined if native CSS hyphenation is supported
});

where in langSettings I can give the testing word (i.e. "FORCEHYPHENOPOLY") and etc. Not sure if this doesn't conflict with the global settings in window.Hyphenopoly.setup. I'm looking forward to see if you like the idea.

Best regards, Petar

mnater commented 3 years ago

This is now available in v5