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.
Param | Type | Description |
---|---|---|
options | Object |
Required. Parameter object. Comprises: |
options.languages | Array |
Required. List of allowed languages. |
options.pathname | String |
Optional. 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}
Param | Type | Description |
---|---|---|
location | Object |
Required. The reference object is similar to window.location . Comprises: |
location.pathname | String |
Required. The path is similar to window.location.pathname . |
location.search | String |
Optional. The request is similar to window.location.search . |
location.hash | String |
Optional. 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}
Param | Type | Description |
---|---|---|
location | String |
Required. The path is similar to window.location.pathname . |
search | String |
Optional. The request is similar to window.location.search . |
hash | String |
Optional. The hash is similar to window.location.hash . |