mirror of
https://github.com/apakabarfm/syllabreak-swift.git
synced 2026-02-18 06:23:16 +00:00
main
syllabreak-swift
Multilingual library for accurate and deterministic hyphenation and syllable counting without relying on dictionaries.
This is a Swift port of syllabreak Python library.
Supported Languages
- 🇬🇧 English (
eng) - 🇷🇺 Russian (
rus) - 🇷🇸 Serbian Cyrillic (
srp-cyrl) - 🇷🇸 Serbian Latin (
srp-latn) - 🇹🇷 Turkish (
tur) - 🇬🇪 Georgian (
kat) - 🇩🇪 German (
deu)
Usage
Auto-detect language
When no language is specified, the library automatically detects the most likely language:
import Syllabreak
let s = Syllabreak(softHyphen: "-")
print(s.syllabify("hello"))
// hel-lo
print(s.syllabify("здраво")) // Serbian Cyrillic
// здра-во
print(s.syllabify("привет")) // Russian
// при-вет
Specify language explicitly
You can specify the language code for more predictable results:
let s = Syllabreak(softHyphen: "-")
print(s.syllabify("problem", lang: "eng")) // Force English rules
// pro-blem
print(s.syllabify("problem", lang: "srp-latn")) // Force Serbian Latin rules
// prob-lem
This is useful when:
- The text could match multiple languages
- You want consistent rules for a specific language
- Processing text in a known language
Language Detection
The library returns all matching languages sorted by confidence:
import Syllabreak
let s = Syllabreak()
print(s.detectLanguage("hello"))
// ["eng", "srp-latn", "tur"] // Matches English, Serbian Latin and Turkish
print(s.detectLanguage("čovek"))
// ["srp-latn", "eng", "tur"] // Serbian Latin has highest confidence due to č
Lines of Code
Languages
Swift
98.1%
Makefile
1.9%