mnater / Hyphenopoly

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

en-us missing, also when not used #184

Closed witoldwegner closed 2 years ago

witoldwegner commented 2 years ago

Hi,

I made a little test where I only included de.wasm and I also only put de.wasm in the patterns folder. Nevertheless it seems to work, Chrome throws this error/warning:

Hyphenopoly.js:27 Error: Element with 'en-us' found, but 'en-us.wasm' not loaded. Check language tags!
    at processElements (Hyphenopoly.js:349:25)
    at Hyphenopoly.js:367:25
    at NodeList.forEach (<anonymous>)
    at Hyphenopoly.js:366:48
    at Array.forEach (<anonymous>)
    at getElems (Hyphenopoly.js:365:29)
    at collectElements (Hyphenopoly.js:380:17)
    at Hyphenopoly.js:901:34

My code:

<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <title>Example 1</title>
        <script src="./Hyphenopoly_Loader.js"></script>
        <script>

        Hyphenopoly.config({
            require: {
                "de": "FORCEHYPHENOPOLY",
            },
            setup: {
                selectors: {
                    ".container": {}
                }
            }
        });
        </script>
        <style type="text/css">
            body {
                width:200px;
                margin-left:20%;
            }
            p {
                text-align: justify;
                margin: 0 2em 0 0;
            }
            .container {
                display: flex;
                hyphens: auto;
                -ms-hyphens: auto;
                -moz-hyphens: auto;
                -webkit-hyphens: auto;
            }
        </style>
    </head>
    <body>
        <h1>Example 1</h1>
        <div class="container">
            <p lang="de">Aus diesem Grund übertreffen auch die Helvetier mit ihrem langen Arbeiterunfallversicherungsgesetz die übrigen aufmerksamkeitsdefizitären Gallier an Tapferkeit, weil sie sich in fast täglichen Gefechten mit den Germanen messen, wobei sie diese entweder von ihrem Gebiet fernhalten als Finanzdienstleistungsunternehmen oder selbst in deren Gebiet kämpfen.</p>
        </div>
    </body>
</html>

Directory-Tree:

├── Hyphenopoly.js
├── Hyphenopoly_Loader.js
├── example.html
└── patterns
    └── de.wasm
mnater commented 2 years ago

Hi

You tell Hyphenopoly to hyphenate the element <div class="container">, it then tries to identify the language of this element. But there's no language set, not on that element, nor on its parents. So Hyphenopoly resorts to the defaultLanguage.

You could either set the defaultLanguage to "de" or put the lang-tag in the <div class="container">.

I hope this helps?

Kind regards, Mathias

witoldwegner commented 2 years ago

Thanks, this absolutely makes sense, I didn’t see this. And thank you also for the quick support, very much appreciated!