Skip to content

Commit

Permalink
Add Czech language (#59)
Browse files Browse the repository at this point in the history
* feat: add czech language

* fix: fix wrong czech word for symbol @
  • Loading branch information
jansvabik authored Oct 13, 2021
1 parent 5f20663 commit 20e9ad2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
6 changes: 6 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{
&csSub,
&deSub,
&enSub,
&esSub,
Expand Down Expand Up @@ -41,6 +42,11 @@ var defaultSub = map[rune]string{
'―': "-", // horizontal bar
}

var csSub = map[rune]string{
'&': "a",
'@': "zavinac",
}

var deSub = map[rune]string{
'&': "und",
'@': "an",
Expand Down
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 "cs", "ces":
slug = SubstituteRune(slug, csSub)
case "de", "deu":
slug = SubstituteRune(slug, deSub)
case "en", "eng":
Expand Down
29 changes: 23 additions & 6 deletions slug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@ func TestSlugMake(t *testing.T) {
{"Ala ma 6 kotów.", "ala-ma-6-kotow"},

{"áÁàÀãÃâÂäÄąĄą̊Ą̊", "aaaaaaaaaaaaaa"},
{"ćĆĉĈçÇ", "cccccc"},
{"éÉèÈẽẼêÊëËęĘ", "eeeeeeeeeeee"},
{"ćĆĉĈçÇčČ", "cccccccc"},
{"éÉèÈẽẼêÊëËęĘěĚ", "eeeeeeeeeeeeee"},
{"íÍìÌĩĨîÎïÏįĮ", "iiiiiiiiiiii"},
{"łŁ", "ll"},
{"ńŃ", "nn"},
{"óÓòÒõÕôÔöÖǫǪǭǬø", "ooooooooooooooo"},
{"śŚ", "ss"},
{"úÚùÙũŨûÛüÜųŲ", "uuuuuuuuuuuu"},
{"y̨Y̨", "yy"},
{"źŹżŹ", "zzzz"},
{"śŚšŠ", "ssss"},
{"řŘ", "rr"},
{"ťŤ", "tt"},
{"úÚùÙũŨûÛüÜųŲůŮ", "uuuuuuuuuuuuuu"},
{"y̨Y̨ýÝ", "yyyy"},
{"źŹżŹžŽ", "zzzzzz"},
{"·/,:;`˜'\"", ""},
{"2000–2013", "2000-2013"},
{"style—not", "style-not"},
Expand Down Expand Up @@ -71,6 +73,10 @@ func TestSlugMakeLang(t *testing.T) {
want string
lowercase bool
}{
{"cs", "ěščřžýáíéúůóňťĚŠČŘŽÝÁÍÉÚŮÓŇŤ", "escrzyaieuuontescrzyaieuuont", true},
{"cs", "ěščřžýáíéúůóňťĚŠČŘŽÝÁÍÉÚŮÓŇŤ", "escrzyaieuuontESCRZYAIEUUONT", false},
{"ces", "ěščřžýáíéúůóňťĚŠČŘŽÝÁÍÉÚŮÓŇŤ", "escrzyaieuuontescrzyaieuuont", true},
{"ces", "ěščřžýáíéúůóňťĚŠČŘŽÝÁÍÉÚŮÓŇŤ", "escrzyaieuuontESCRZYAIEUUONT", false},
{"de", "Wir mögen Bücher & Käse", "wir-moegen-buecher-und-kaese", true},
{"de", "Wir mögen Bücher & Käse", "Wir-moegen-Buecher-und-Kaese", false},
{"de", "Äpfel Über Österreich", "aepfel-ueber-oesterreich", true},
Expand All @@ -86,6 +92,14 @@ func TestSlugMakeLang(t *testing.T) {
{"kk", "әғһіңөқұүӘҒҺІҢӨҚҰҮ", "aghinoquuaghinoquu", true},
{"kk", "әғһіңөқұүӘҒҺІҢӨҚҰҮ", "aghinoquuAGHINOQUU", false},
// & fun.
{"cs", "Toto & Tamto", "toto-a-tamto", true},
{"cs", "Toto & Tamto", "Toto-a-Tamto", false},
{"cs", "Toto @ Tamto", "toto-zavinac-tamto", true},
{"cs", "Toto @ Tamto", "Toto-zavinac-Tamto", false},
{"ces", "Toto & Tamto", "toto-a-tamto", true},
{"ces", "Toto & Tamto", "Toto-a-Tamto", false},
{"ces", "Toto @ Tamto", "toto-zavinac-tamto", true},
{"ces", "Toto @ Tamto", "Toto-zavinac-Tamto", false},
{"de", "This & that", "this-und-that", true},
{"en", "This & that", "this-and-that", true},
{"es", "This & that", "this-y-that", true},
Expand Down Expand Up @@ -116,6 +130,7 @@ func TestSlugMakeLang(t *testing.T) {
{"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.
{"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},
{"es", "1\"2'3’4‒5–6—7―8", "1234-5-6-7-8", true},
Expand Down Expand Up @@ -151,6 +166,8 @@ func TestSlugMakeUserSubstituteLang(t *testing.T) {
}{
{map[string]string{"'": " "}, "en", "That's great", "that-s-great"},
{map[string]string{"&": "or"}, "en", "This & that", "this-or-that"}, // by default "&" => "and"
{map[string]string{"&": "or"}, "cs", "This & that", "this-or-that"}, // by default "&" => "a"
{map[string]string{"&": "or"}, "ces", "This & that", "this-or-that"}, // by default "&" => "a"
{map[string]string{"&": "or"}, "de", "This & that", "this-or-that"}, // by default "&" => "und"
{map[string]string{"&": "or"}, "DEU", "This & that", "this-or-that"}, // by default "&" => "und"
{map[string]string{"&": "or"}, "Fin", "This & that", "this-or-that"}, // by default "&" => "ja"
Expand Down

0 comments on commit 20e9ad2

Please sign in to comment.