Skip to content

Commit

Permalink
Adds support for Bulgarian language (#66)
Browse files Browse the repository at this point in the history
* Adds support for Bulgarian language
* Alphabetic sort

Co-authored-by: Dobrosław Żybort <matrixik@gmail.com>
  • Loading branch information
aquilax and matrixik committed Sep 27, 2022
1 parent f0752d5 commit d412da9
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
64 changes: 64 additions & 0 deletions languages_substitution.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ func init() {
// TODO: Find better way so all langs are merged automatically and better
// tested.
for _, sub := range []*map[rune]string{
&bgSub,
&csSub,
&deSub,
&enSub,
Expand Down Expand Up @@ -189,3 +190,66 @@ var trSub = map[rune]string{
'ç': "c",
'Ç': "C",
}

var bgSub = map[rune]string{
'А': "A",
'Б': "B",
'В': "V",
'Г': "G",
'Д': "D",
'Е': "E",
'Ж': "Zh",
'З': "Z",
'И': "I",
'Й': "Y",
'К': "K",
'Л': "L",
'М': "M",
'Н': "N",
'О': "O",
'П': "P",
'Р': "R",
'С': "S",
'Т': "T",
'У': "U",
'Ф': "F",
'Х': "H",
'Ц': "Ts",
'Ч': "Ch",
'Ш': "Sh",
'Щ': "Sh",
'Ъ': "A",
'Ь': "Y",
'Ю': "Yu",
'Я': "Ya",
'а': "a",
'б': "b",
'в': "v",
'г': "g",
'д': "d",
'е': "e",
'ж': "zh",
'з': "z",
'и': "i",
'й': "y",
'к': "k",
'л': "l",
'м': "m",
'н': "n",
'о': "o",
'п': "p",
'р': "r",
'с': "s",
'т': "t",
'у': "u",
'ф': "f",
'х': "h",
'ц': "ts",
'ч': "ch",
'ш': "sh",
'щ': "sht",
'ъ': "a",
'ь': "y",
'ю': "yu",
'я': "ya",
}
2 changes: 2 additions & 0 deletions slug.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ func MakeLang(s string, lang string) (slug string) {
// Process string with selected substitution language.
// Catch ISO 3166-1, ISO 639-1:2002 and ISO 639-3:2007.
switch strings.ToLower(lang) {
case "bg", "bgr":
slug = SubstituteRune(slug, bgSub)
case "cs", "ces":
slug = SubstituteRune(slug, csSub)
case "de", "deu":
Expand Down
6 changes: 6 additions & 0 deletions slug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ func TestSlugMakeLang(t *testing.T) {
want string
lowercase bool
}{
{"bg", "АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЬЮЯабвгдежзийклмнопрстуфхцчшщъьюя", "abvgdezhziyklmnoprstufhtschshshayyuyaabvgdezhziyklmnoprstufhtschshshtayyuya", true},
{"bg", "АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЬЮЯабвгдежзийклмнопрстуфхцчшщъьюя", "ABVGDEZhZIYKLMNOPRSTUFHTsChShShAYYuYaabvgdezhziyklmnoprstufhtschshshtayyuya", false},
{"cs", "ěščřžýáíéúůóňťĚŠČŘŽÝÁÍÉÚŮÓŇŤ", "escrzyaieuuontescrzyaieuuont", true},
{"cs", "ěščřžýáíéúůóňťĚŠČŘŽÝÁÍÉÚŮÓŇŤ", "escrzyaieuuontESCRZYAIEUUONT", false},
{"ces", "ěščřžýáíéúůóňťĚŠČŘŽÝÁÍÉÚŮÓŇŤ", "escrzyaieuuontescrzyaieuuont", true},
Expand All @@ -94,7 +96,9 @@ func TestSlugMakeLang(t *testing.T) {
{"tr", "şüöğıçŞÜÖİĞÇ", "suogicSUOIGC", false},
{"kk", "әғһіңөқұүӘҒҺІҢӨҚҰҮ", "aghinoquuaghinoquu", true},
{"kk", "әғһіңөқұүӘҒҺІҢӨҚҰҮ", "aghinoquuAGHINOQUU", false},

// & fun.
{"bg", "Това и онова", "tova-i-onova", true},
{"cs", "Toto & Tamto", "toto-a-tamto", true},
{"cs", "Toto & Tamto", "Toto-a-Tamto", false},
{"cs", "Toto @ Tamto", "toto-zavinac-tamto", true},
Expand Down Expand Up @@ -132,8 +136,10 @@ func TestSlugMakeLang(t *testing.T) {
{"sl", "đanković & Kožušček", "dzankovic-in-kozuscek", true},
{"sl", "ĐankoVIĆ & KOŽUŠČEK", "DZankoVIC-in-KOZUSCEK", false},
{"test", "This & that", "this-and-that", true}, // unknown lang, fallback to "en"

// Test defaultSub, when adding new lang copy/paste this line,
// it contain special characters.
{"bg", "1\"2'3’4‒5–6—7―8", "1234-5-6-7-8", true},
{"cs", "1\"2'3’4‒5–6—7―8", "1234-5-6-7-8", true},
{"de", "1\"2'3’4‒5–6—7―8", "1234-5-6-7-8", true},
{"en", "1\"2'3’4‒5–6—7―8", "1234-5-6-7-8", true},
Expand Down

0 comments on commit d412da9

Please sign in to comment.