From 9da696dcc420ce5fc336946a99f094111a486330 Mon Sep 17 00:00:00 2001 From: Stanislav Gumeniuk Date: Fri, 18 Oct 2019 15:30:49 +0600 Subject: [PATCH 1/2] Add kazakh language --- languages_substitution.go | 25 ++++++++++++++++++++++++- slug.go | 2 ++ slug_test.go | 5 +++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/languages_substitution.go b/languages_substitution.go index 3ba3bcd..a0ced0e 100644 --- a/languages_substitution.go +++ b/languages_substitution.go @@ -8,7 +8,7 @@ package slug func init() { // Merge language subs with the default one for _, sub := range []*map[rune]string{ - &deSub, &enSub, &esSub, &fiSub, &grSub, &nlSub, &plSub, &svSub, + &deSub, &enSub, &esSub, &fiSub, &grSub, &nlSub, &plSub, &svSub, &kkSub, } { for key, value := range defaultSub { (*sub)[key] = value @@ -100,3 +100,26 @@ var trSub = map[rune]string{ 'ç': "c", 'Ç': "C", } + +var kkSub = map[rune]string{ + '&': "jane", + 'ә': "a", + 'ғ': "g", + 'һ': "h", + 'і': "i", + 'ң': "n", + 'ө': "o", + 'қ': "q", + 'ұ': "u", + 'ү': "u", + + 'Ә': "A", + 'Ғ': "G", + 'Һ': "H", + 'І': "I", + 'Ң': "N", + 'Ө': "O", + 'Қ': "Q", + 'Ұ': "U", + 'Ү': "U", +} diff --git a/slug.go b/slug.go index b14f7d8..61aca35 100644 --- a/slug.go +++ b/slug.go @@ -75,6 +75,8 @@ func MakeLang(s string, lang string) (slug string) { slug = SubstituteRune(slug, svSub) case "tr", "tur": slug = SubstituteRune(slug, trSub) + case "kz", "kk", "kaz": + slug = SubstituteRune(slug, kkSub) default: // fallback to "en" if lang not found slug = SubstituteRune(slug, enSub) } diff --git a/slug_test.go b/slug_test.go index 911ccf4..e882ae9 100644 --- a/slug_test.go +++ b/slug_test.go @@ -80,6 +80,8 @@ func TestSlugMakeLang(t *testing.T) { {"Ell", "ϊχώΩϋ", "ixwwu", false}, {"tr", "şüöğıçŞÜÖİĞÇ", "suogicsuoigc", true}, {"tr", "şüöğıçŞÜÖİĞÇ", "suogicSUOIGC", false}, + {"kk", "әғһіңөқұүӘҒҺІҢӨҚҰҮ", "aghinoquuaghinoquu", true}, + {"kk", "әғһіңөқұүӘҒҺІҢӨҚҰҮ", "aghinoquuAGHINOQUU", false}, // & fun. {"de", "This & that", "this-und-that", true}, {"en", "This & that", "this-and-that", true}, @@ -96,6 +98,7 @@ func TestSlugMakeLang(t *testing.T) { {"swe", "This & that", "this-och-that", true}, {"swe", "This @ that", "this-snabel-a-that", true}, {"tr", "This & that", "this-ve-that", true}, + {"kk", "This & that", "this-jane-that", true}, {"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. @@ -106,6 +109,7 @@ func TestSlugMakeLang(t *testing.T) { {"gr", "1\"2'3’4‒5–6—7―8", "1234-5-6-7-8", true}, {"nl", "1\"2'3’4‒5–6—7―8", "1234-5-6-7-8", true}, {"pl", "1\"2'3’4‒5–6—7―8", "1234-5-6-7-8", true}, + {"kk", "1\"2'3’4‒5–6—7―8", "1234-5-6-7-8", true}, } for index, smlt := range testCases { @@ -131,6 +135,7 @@ func TestSlugMakeUserSubstituteLang(t *testing.T) { {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" + {map[string]string{"&": "or"}, "kk", "This & that", "this-or-that"}, // by default "&" => "jane" {map[string]string{"&": "or", "@": "the"}, "sv", "@ This & that", "the-this-or-that"}, // by default "&" => "och", "@" => "snabel a" {map[string]string{"&": "or", "@": "the"}, "de", "@ This & that", "the-this-or-that"}, // by default "&" => "und", "@" => "an" } From 82b66a0ba09daebefb9f72e86ee9bfbf294820d2 Mon Sep 17 00:00:00 2001 From: Stanislav Gumeniuk Date: Sun, 20 Oct 2019 17:46:54 +0600 Subject: [PATCH 2/2] fix order --- languages_substitution.go | 13 +++---------- slug.go | 4 ++-- slug_test.go | 5 +++-- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/languages_substitution.go b/languages_substitution.go index a0ced0e..4c492ad 100644 --- a/languages_substitution.go +++ b/languages_substitution.go @@ -8,7 +8,7 @@ package slug func init() { // Merge language subs with the default one for _, sub := range []*map[rune]string{ - &deSub, &enSub, &esSub, &fiSub, &grSub, &nlSub, &plSub, &svSub, &kkSub, + &deSub, &enSub, &esSub, &fiSub, &grSub, &kkSub, &nlSub, &plSub, &svSub, } { for key, value := range defaultSub { (*sub)[key] = value @@ -105,21 +105,14 @@ var kkSub = map[rune]string{ '&': "jane", 'ә': "a", 'ғ': "g", - 'һ': "h", - 'і': "i", + 'қ': "q", 'ң': "n", 'ө': "o", - 'қ': "q", 'ұ': "u", - 'ү': "u", - 'Ә': "A", 'Ғ': "G", - 'Һ': "H", - 'І': "I", + 'Қ': "Q", 'Ң': "N", 'Ө': "O", - 'Қ': "Q", 'Ұ': "U", - 'Ү': "U", } diff --git a/slug.go b/slug.go index 61aca35..272cc3f 100644 --- a/slug.go +++ b/slug.go @@ -67,6 +67,8 @@ func MakeLang(s string, lang string) (slug string) { slug = SubstituteRune(slug, fiSub) case "gr", "el", "ell": slug = SubstituteRune(slug, grSub) + case "kz", "kk", "kaz": + slug = SubstituteRune(slug, kkSub) case "nl", "nld": slug = SubstituteRune(slug, nlSub) case "pl", "pol": @@ -75,8 +77,6 @@ func MakeLang(s string, lang string) (slug string) { slug = SubstituteRune(slug, svSub) case "tr", "tur": slug = SubstituteRune(slug, trSub) - case "kz", "kk", "kaz": - slug = SubstituteRune(slug, kkSub) default: // fallback to "en" if lang not found slug = SubstituteRune(slug, enSub) } diff --git a/slug_test.go b/slug_test.go index e882ae9..f0d6c95 100644 --- a/slug_test.go +++ b/slug_test.go @@ -90,6 +90,8 @@ func TestSlugMakeLang(t *testing.T) { {"gr", "This & that", "this-kai-that", true}, {"ell", "This & that", "this-kai-that", true}, {"Ell", "This & that", "this-kai-that", true}, + {"kk", "This & that", "this-jane-that", true}, + {"kk", "This @ that", "this-that", true}, {"nl", "This & that", "this-en-that", true}, {"pl", "This & that", "this-i-that", true}, {"pol", "This & that", "this-i-that", true}, @@ -98,7 +100,6 @@ func TestSlugMakeLang(t *testing.T) { {"swe", "This & that", "this-och-that", true}, {"swe", "This @ that", "this-snabel-a-that", true}, {"tr", "This & that", "this-ve-that", true}, - {"kk", "This & that", "this-jane-that", true}, {"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. @@ -107,9 +108,9 @@ func TestSlugMakeLang(t *testing.T) { {"es", "1\"2'3’4‒5–6—7―8", "1234-5-6-7-8", true}, {"fi", "1\"2'3’4‒5–6—7―8", "1234-5-6-7-8", true}, {"gr", "1\"2'3’4‒5–6—7―8", "1234-5-6-7-8", true}, + {"kk", "1\"2'3’4‒5–6—7―8", "1234-5-6-7-8", true}, {"nl", "1\"2'3’4‒5–6—7―8", "1234-5-6-7-8", true}, {"pl", "1\"2'3’4‒5–6—7―8", "1234-5-6-7-8", true}, - {"kk", "1\"2'3’4‒5–6—7―8", "1234-5-6-7-8", true}, } for index, smlt := range testCases {