Dosiero demo: languages

Demo only. Everything you upload is visible to every other visitor of this demo, and is deleted again within minutes. Actions are logged, including your IP address. Do not upload anything private, unlawful, or that you are not entitled to share.

English is built in; the package ships five more as JSON files under langs/. Every cell below is a separate instance with a different one loaded, so the labels, the dialogs and the upload notices all change together — and nothing but translations differs between them.

Integration

With a bundler, import the language you need. No request, and a wrong key is a compile error:

import cs from '@zdenekgebauer/dosiero/langs/cs.json';

new Dosiero({translations: cs, /* … */}).open();

Without a build step, fetch it through the helper, which knows where the package's own files live — this is what this page does:

<script type="module">
    import {Dosiero} from '/dosiero/dosiero.min.mjs';

    const translations = await Dosiero.loadLanguage('cs');

    new Dosiero({
        mode: Dosiero.MODE_IFRAME,
        iframe: document.getElementById('iframe1'),
        endpoint: window.location.origin + '/endpoint/index.php',
        translations: translations,
    }).open();
</script>

Await the language before constructing. The configuration is read when the instance is built and open() has to stay synchronous, so there is no point later where the manager could wait for a file. Each url is fetched once, however many instances ask for it — this page builds six managers from six requests.

A language may be partial: whatever it leaves out keeps the built-in English. Because translations is a plain object, overriding single labels is a spread:

new Dosiero({translations: {...cs, buttonUpload: 'Nahrát soubory'}}).open();

The options are read when the manager opens, so switching language at runtime means destroy() and a new instance.

back