0.36.0 • Published 4 years ago

@narando/express-preferred-ui-language v0.36.0

Weekly downloads
25
License
UNLICENSED
Repository
gitlab
Last release
4 years ago

@narando/express-preferred-ui-language

A middleware to set the available system languages for use with mustache.

Getting Started

You need to have nodejs, npm, express and mustache installed.

$ npm install @narando/express-preferred-ui-language

Usage

The middleware will get the availabel languages from ./app/locales/:

import preferredUILanguage from "@narando/express-preferred-ui-language";

// add middleware to express
app.router(preferredUILanguage());

To add a language you have to create a new file at ./app/locales. The file name will be used as the language identifier.

Use the following JSON structure and folder structure

Folder structure

app
|-locales
  |-de-DE.json
  |-en-US.json

Locale file structure

{
  "namespace1": {
    "text1": "First text",
    "text2": "Second text"
  },
  "namespace2": {
    "text3": "Third text",
    "text4": "Fourth text"
  }
}

The middleware will set the res.locals like:

[
  { languageCode: "de-DE", selected: true },
  { languageCode: "en-US", selected: false }
]

To use it in your mustache template you can use the following example to create a dropdown with all available languages

<select name="systemLanguage" id="selectSystemLanguage" class="selectpicker form-control" data-live-search="true">
  {{#UILanguage}}
      <option value="{{languageCode}}" {{#selected}} selected {{/selected}}>{{languageCode}}</option>
  {{/UILanguage}}
</select>
0.36.0

4 years ago

0.35.0

5 years ago

0.34.1

5 years ago

0.34.0

5 years ago

0.33.0

5 years ago

0.32.0

5 years ago

0.31.0

5 years ago

0.30.0

6 years ago

0.29.0

6 years ago

0.28.5

6 years ago

0.28.4

6 years ago

0.28.2

6 years ago

0.28.0

6 years ago

0.27.0

6 years ago

0.26.1

6 years ago

0.25.0

6 years ago

0.24.1

6 years ago

0.24.0

6 years ago

0.23.1

6 years ago

0.23.0

6 years ago