url2lang
v0.1.8
Published
url2lang returns the language code from the language information contained in the url.
Downloads
179
Readme
url2lang
url2lang returns the language code from the language information contained in the url.
Installation
npm install url2langUsage
import url2lang from 'url2lang'
const lang = url2lang(window.location.pathname)
console.log(lang)
// enExamples
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'Supported Languages
The library currently supports 20 languages:
- English (
en) - Japanese (
ja) - Italian (
it) - Korean (
ko) - French (
fr) - Indonesian (
id) - Chinese Simplified (
zh-cn) - Chinese Traditional (
zh-tw) - Spanish (
es) - Arabic (
ar) - Portuguese (
pt) - German (
de) - Russian (
ru) - Polish (
pl) - Ukrainian (
uk) - Greek (
el) - Turkish (
tr) - Latvian (
lv) - Thai (
th) - Bengali (
bn)
License
MIT
