From 20e9ad20eee911999391d0814e449ab0deb2ff4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C5=A0v=C3=A1b=C3=ADk?= <30616446+jansvabik@users.noreply.github.com> Date: Wed, 13 Oct 2021 20:30:04 +0200 Subject: [PATCH] Add Czech language (#59) * feat: add czech language * fix: fix wrong czech word for symbol @ --- languages_substitution.go | 6 ++++++ slug.go | 2 ++ slug_test.go | 29 +++++++++++++++++++++++------ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/languages_substitution.go b/languages_substitution.go index 823ddd5..f7ab294 100644 --- a/languages_substitution.go +++ b/languages_substitution.go @@ -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, @@ -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", diff --git a/slug.go b/slug.go index fe92c9b..2917bbf 100644 --- a/slug.go +++ b/slug.go @@ -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": diff --git a/slug_test.go b/slug_test.go index 6184f0e..9376c7c 100644 --- a/slug_test.go +++ b/slug_test.go @@ -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"}, @@ -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}, @@ -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}, @@ -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}, @@ -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"