Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add language substitution for swedish #37

Merged
merged 1 commit into from
Oct 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion languages_substitution.go
Original file line number Diff line number Diff line change
@@ -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
@@ -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",
2 changes: 2 additions & 0 deletions slug.go
Original file line number Diff line number Diff line change
@@ -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
11 changes: 8 additions & 3 deletions slug_test.go
Original file line number Diff line number Diff line change
@@ -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},
@@ -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,
@@ -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"
}