Skip to content

Commit

Permalink
Add language substitution for swedish (#37)
Browse files Browse the repository at this point in the history
This adds a language substitution for & and @ in swedish.
  • Loading branch information
antonlindstrom authored and matrixik committed Oct 7, 2019
1 parent 984b6d1 commit a57e999
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
7 changes: 6 additions & 1 deletion languages_substitution.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
&deSub, &enSub, &esSub, &fiSub, &grSub, &nlSub, &plSub, &svSub,
} {
for key, value := range defaultSub {
(*sub)[key] = value
Expand Down Expand Up @@ -79,6 +79,11 @@ var plSub = map[rune]string{
'@': "na",
}

var svSub = map[rune]string{
'&': "och",
'@': "snabel a",
}

var trSub = map[rune]string{
'&': "ve",
'@': "et",
Expand Down
2 changes: 2 additions & 0 deletions slug.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ func MakeLang(s string, lang string) (slug string) {
slug = SubstituteRune(slug, nlSub)
case "pl", "pol":
slug = SubstituteRune(slug, plSub)
case "sv", "swe":
slug = SubstituteRune(slug, svSub)
case "tr", "tur":
slug = SubstituteRune(slug, trSub)
default: // fallback to "en" if lang not found
Expand Down
11 changes: 8 additions & 3 deletions slug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ func TestSlugMake(t *testing.T) {

func TestSlugMakeLang(t *testing.T) {
testCases := []struct {
lang string
in string
want string
lang string
in string
want string
lowercase bool
}{
{"de", "Wir mögen Bücher & Käse", "wir-moegen-buecher-und-kaese", true},
Expand All @@ -91,6 +91,10 @@ func TestSlugMakeLang(t *testing.T) {
{"nl", "This & that", "this-en-that", true},
{"pl", "This & that", "this-i-that", true},
{"pol", "This & that", "this-i-that", true},
{"sv", "This & that", "this-och-that", true},
{"sv", "This @ that", "this-snabel-a-that", true},
{"swe", "This & that", "this-och-that", true},
{"swe", "This @ that", "this-snabel-a-that", true},
{"tr", "This & that", "this-ve-that", true},
{"test", "This & that", "this-and-that", true}, // unknown lang, fallback to "en"
// Test defaultSub, when adding new lang copy/paste this line,
Expand Down Expand Up @@ -127,6 +131,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", "@": "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"
}

Expand Down

0 comments on commit a57e999

Please sign in to comment.