1.1.2 • Published 6 years ago

multi-languages-url v1.1.2

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

Multi Languages URL

This simple tool for creating URL links adapted to the current language of the web application.

Installing

$ npm install --save multi-languages-url

Usage

import MultiLanguagesURL from 'multi-languages-url';
...
const ml = new MultiLanguagesURL({languages: ['en', 'de', 'ru']});
...
<a href={ml.url('/blog', '?q=last', '#news')}>Blog</a>
or
<a href={ml.url({pathname: '/blog', search: '?q=last', hash: '#news'})}>Blog</a>

MultiLanguagesURL

Kind: global class
this: {MultiLanguagesURL}
Author: Alexander Ivannikov a.n.ivannikov@yandex.ru (https://github.com/an-ivannikov)

new MultiLanguagesURL(options)

The class of the multilanguage page location url. Extracts from window.location.pathname one of the list of valid languages ​​and insertes it at the beginning of the incoming location url.

Forms the base of the path this.rootLanguagePath for subsequent substitution to the incoming location url.

ParamTypeDescription
optionsObjectRequired. Parameter object. Comprises:
options.languagesArrayRequired. List of allowed languages.
options.pathnameStringOptional. The default path is window.location.pathname.

multiLanguagesURL.url(location) ⇒ String

The method substitutes the created path base to the incoming location url.

Kind: instance method of MultiLanguagesURL
Returns: String - A reference of the form this.rootLanguagePath + /pathname + search +hash.
this: {MultiLanguagesURL}

ParamTypeDescription
locationObjectRequired. The reference object is similar to window.location. Comprises:
location.pathnameStringRequired. The path is similar to window.location.pathname.
location.searchStringOptional. The request is similar to window.location.search.
location.hashStringOptional. The hash is similar to window.location.hash.

multiLanguagesURL.url(location, search, hash) ⇒ String

The method substitutes the created path base to the incoming location url.

Kind: instance method of MultiLanguagesURL
Returns: String - A reference of the form this.rootLanguagePath + /pathname + search +hash.
this: {MultiLanguagesURL}

ParamTypeDescription
locationStringRequired. The path is similar to window.location.pathname.
searchStringOptional. The request is similar to window.location.search.
hashStringOptional. The hash is similar to window.location.hash.