Transliterate
Convert Unicode characters to Latin characters using transliteration
Install / Use
/learn @sindresorhus/TransliterateREADME
transliterate
Convert Unicode characters to Latin characters using transliteration
Can be useful for slugification purposes and other times you cannot use Unicode.
Install
npm install @sindresorhus/transliterate
Usage
import transliterate from '@sindresorhus/transliterate';
transliterate('Fußgängerübergänge');
//=> 'Fussgaengeruebergaenge'
transliterate('Я люблю единорогов');
//=> 'Ya lyublyu edinorogov'
transliterate('أنا أحب حيدات');
//=> 'ana ahb hydat'
transliterate('tôi yêu những chú kỳ lân');
//=> 'toi yeu nhung chu ky lan'
transliterate('En–dashes and em—dashes are normalized');
//=> 'En-dashes and em-dashes are normalized'
API
transliterate(string, options?)
string
Type: string
String to transliterate.
options
Type: object
customReplacements
Type: Array<string[]> | Map<string, string>
Default: []
Add your own custom replacements.
The replacements are run on the original string before any other transformations.
This only overrides a default replacement if you set an item with the same key.
import transliterate from '@sindresorhus/transliterate';
transliterate('Я люблю единорогов', {
customReplacements: [
['единорогов', '🦄']
]
})
//=> 'Ya lyublyu 🦄'
You can also pass a Map:
transliterate('foo & bar', {
customReplacements: new Map([
['&', 'and']
])
})
//=> 'foo and bar'
locale
Type: string
BCP-47 language tag for language-specific transliteration.
When specified, uses language-specific replacement rules for characters that have different transliterations in different languages.
import transliterate from '@sindresorhus/transliterate';
// Swedish: ä→a, ö→o, å→a
transliterate('Räksmörgås', {locale: 'sv'});
//=> 'Raksmorgas'
// German: ä→ae, ö→oe
transliterate('Räksmörgås', {locale: 'de'});
//=> 'Raeksmoergas'
Supported locales
The following locales have specific replacement rules when using the locale option:
da- Danishde- Germanhu- Hungariannb- Norwegian Bokmålsr- Serbiansv- Swedishtr- Turkish
Supported languages
Most major languages are supported.
This includes special handling for:
- Arabic
- Armenian
- Czech
- Danish
- Dhivehi
- Georgian
- German (umlauts)
- Greek
- Hungarian
- Latin
- Latvian
- Lithuanian
- Macedonian
- Pashto
- Persian
- Polish
- Romanian
- Russian
- Serbian
- Slovak
- Swedish
- Turkish
- Ukrainian
- Urdu
- Vietnamese
However, Chinese is currently not supported.
Related
- slugify - Slugify a string
Related Skills
node-connect
352.5kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
111.3kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
352.5kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
352.5kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
