@lokse/plugin-fallback

Plugin for fallbacking missing translations to the default language translation.

Usage no npm install needed!

<script type="module">
  import loksePluginFallback from 'https://cdn.skypack.dev/@lokse/plugin-fallback';
</script>

README

@lokse/plugin-fallback

Plugin for fallbacking missing translations to the default language translation.

Installation

$ yarn add -D @lokse/plugin-fallback

Usage

Add it into plugins section of lokse config, and pass an options with default language

{
    "plugins": [
        { 
            "name": "@lokse/plugin-fallback", 
            "options": { 
                "defaultLanguage": "en-GB" 
            }
        }
    ]
}

Then if you spreadsheet contains data like this

key_web en-GB cs-CZ de-De
auth.username Username Nutzername
auth.password Password Heslo
auth.login Login Přihlásit Einloggen

Then the gaps in translations will be filled with default language translations and output will look like this

// en-GB
{
    "auth.username": "Username",
    "auth.password": "Password",
    "auth.login": "Login"
}
// cs-CZ
{
    "auth.username": "Username",
    "auth.password": "Heslo",
    "auth.login": "Přihlásit"
}
// de-De
{
    "auth.username": "Nutzername",
    "auth.password": "Password",
    "auth.login": "Einloggen"
}

Options

defaultLanguage: string

{
    ...
    "options": { 
        "defaultLanguage": "en-GB" 
    }
}

Required. Determines language used to fill missing gaps in translations.

logMissingFallback: boolean

Optional. Defaults to true. Determines logging of missing translations in default language.

Logs only when fallbacking is invoked. For example if there will be no en-GB translation for auth.username key in previous example, plugin warns about that fact. But that doesn't apply for auth.login as there is no need for translation fallbacking because there are all translations filled.

Loggin can be turned off with

{
    ...
    "options": { 
        "logMissingFallback": false
    }
}

License

Lokse is licensed under the MIT License. Documentation is licensed under Creative Commons License. Created with ♥ by @horaklukas and all the great contributors.