Skip to content

Commit

Permalink
Fix langs alphabetic order in the code (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
matrixik authored Jul 26, 2021
1 parent a0807d1 commit fe566fd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
25 changes: 19 additions & 6 deletions languages_substitution.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,20 @@ func init() {
// TODO: Find better way so all langs are merged automatically and better
// tested.
for _, sub := range []*map[rune]string{
&deSub, &enSub, &esSub, &fiSub, &frSub, &grSub, &kkSub, &nlSub, &plSub, &svSub, &slSub, &trSub, &nbSub, &nnSub,
&deSub,
&enSub,
&esSub,
&fiSub,
&frSub,
&grSub,
&kkSub,
&nbSub,
&nlSub,
&nnSub,
&plSub,
&slSub,
&svSub,
&trSub,
} {
for key, value := range defaultSub {
(*sub)[key] = value
Expand Down Expand Up @@ -116,17 +129,17 @@ var plSub = map[rune]string{
'@': "na",
}

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

var slSub = map[rune]string{
'&': "in",
'Đ': "DZ",
'đ': "dz",
}

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

var trSub = map[rune]string{
'&': "ve",
'@': "et",
Expand Down
12 changes: 6 additions & 6 deletions slug.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,18 @@ func MakeLang(s string, lang string) (slug string) {
slug = SubstituteRune(slug, grSub)
case "kz", "kk", "kaz":
slug = SubstituteRune(slug, kkSub)
case "nb", "nob":
slug = SubstituteRune(slug, nbSub)
case "nl", "nld":
slug = SubstituteRune(slug, nlSub)
case "pl", "pol":
slug = SubstituteRune(slug, plSub)
case "sv", "swe":
slug = SubstituteRune(slug, svSub)
case "nn", "nno":
slug = SubstituteRune(slug, nnSub)
case "nb", "nob":
slug = SubstituteRune(slug, nbSub)
case "pl", "pol":
slug = SubstituteRune(slug, plSub)
case "sl", "slv":
slug = SubstituteRune(slug, slSub)
case "sv", "swe":
slug = SubstituteRune(slug, svSub)
case "tr", "tur":
slug = SubstituteRune(slug, trSub)
default: // fallback to "en" if lang not found
Expand Down
9 changes: 5 additions & 4 deletions slug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestSlugMake(t *testing.T) {
{"Æ", "ae"},
{"Ich heiße", "ich-heisse"},
{"𐀀", ""}, // Bug #53
{"% 5 @ 4 $ 3 / 2 & 1 & 2 # 3 @ 4 _ 5", "5-at-4-3-2-and-1-and-2-3-at-4-_-5"},

{"This & that", "this-and-that"},
{"fácil €", "facil-eu"},
Expand Down Expand Up @@ -121,12 +122,12 @@ func TestSlugMakeLang(t *testing.T) {
{"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},
{"sv", "1\"2'3’4‒5–6—7―8", "1234-5-6-7-8", true},
{"nb", "1\"2'3’4‒5–6—7―8", "1234-5-6-7-8", true},
{"nn", "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},
{"sl", "1\"2'3’4-5–6—7―8", "1234-5-6-7-8", true},
{"sv", "1\"2'3’4‒5–6—7―8", "1234-5-6-7-8", true},
{"tr", "1\"2'3’4‒5–6—7―8", "1234-5-6-7-8", true},
}

Expand Down Expand Up @@ -155,8 +156,8 @@ func TestSlugMakeUserSubstituteLang(t *testing.T) {
{map[string]string{"&": "or"}, "Fin", "This & that", "this-or-that"}, // by default "&" => "ja"
{map[string]string{"&": "or"}, "fr", "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"
{map[string]string{"&": "or", "@": "the"}, "sv", "@ This & that", "the-this-or-that"}, // by default "&" => "och", "@" => "snabel a"
}

for index, smust := range testCases {
Expand Down

0 comments on commit fe566fd

Please sign in to comment.