url2lang returns the language code from the language information contained in the url.
npm install url2langurl2lang returns the language code from the language information contained in the url.
``bash`
npm install url2lang
`js
import url2lang from 'url2lang'
const lang = url2lang(window.location.pathname)
console.log(lang)
// en
`
`js
import url2lang from 'url2lang'
// Various URL patterns
url2lang('/en/about') // 'en'
url2lang('/ja/products/item') // 'ja'
url2lang('/zh-cn/contact') // 'zh-cn'
url2lang('/unknown/path') // 'unknown'
url2lang('/home') // 'unknown'
`
The library currently supports 20 languages:
- English (en)ja
- Japanese () it
- Italian ()ko
- Korean ()fr
- French ()id
- Indonesian ()zh-cn
- Chinese Simplified ()zh-tw
- Chinese Traditional ()es
- Spanish ()ar
- Arabic ()pt
- Portuguese ()de
- German ()ru
- Russian ()pl
- Polish ()uk
- Ukrainian ()el
- Greek ()tr
- Turkish ()lv
- Latvian ()th
- Thai ()bn`)
- Bengali (
MIT