From 17271d5e820a79fb96e8f48deecf6fcabf41bf36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C5=A0v=C3=A1b=C3=ADk?= Date: Sun, 3 Oct 2021 14:03:24 +0200 Subject: [PATCH 1/2] feat: add czech language --- 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..4888ac3 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", + '@': "apostrof", +} + 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..8cdbf3f 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-apostrof-tamto", true}, + {"cs", "Toto @ Tamto", "Toto-apostrof-Tamto", false}, + {"ces", "Toto & Tamto", "toto-a-tamto", true}, + {"ces", "Toto & Tamto", "Toto-a-Tamto", false}, + {"ces", "Toto @ Tamto", "toto-apostrof-tamto", true}, + {"ces", "Toto @ Tamto", "Toto-apostrof-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" From 6831718b96cf49dcc66a2582a2b167a188b78df7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C5=A0v=C3=A1b=C3=ADk?= Date: Thu, 7 Oct 2021 21:49:55 +0200 Subject: [PATCH 2/2] fix: fix wrong czech word for symbol @ --- languages_substitution.go | 2 +- slug_test.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/languages_substitution.go b/languages_substitution.go index 4888ac3..f7ab294 100644 --- a/languages_substitution.go +++ b/languages_substitution.go @@ -44,7 +44,7 @@ var defaultSub = map[rune]string{ var csSub = map[rune]string{ '&': "a", - '@': "apostrof", + '@': "zavinac", } var deSub = map[rune]string{ diff --git a/slug_test.go b/slug_test.go index 8cdbf3f..9376c7c 100644 --- a/slug_test.go +++ b/slug_test.go @@ -94,12 +94,12 @@ func TestSlugMakeLang(t *testing.T) { // & fun. {"cs", "Toto & Tamto", "toto-a-tamto", true}, {"cs", "Toto & Tamto", "Toto-a-Tamto", false}, - {"cs", "Toto @ Tamto", "toto-apostrof-tamto", true}, - {"cs", "Toto @ Tamto", "Toto-apostrof-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-apostrof-tamto", true}, - {"ces", "Toto @ Tamto", "Toto-apostrof-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},