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 kazakh language #40

Merged
merged 2 commits into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 24 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, &svSub,
&deSub, &enSub, &esSub, &fiSub, &grSub, &nlSub, &plSub, &svSub, &kkSub,
gumeniukcom marked this conversation as resolved.
Show resolved Hide resolved
} {
for key, value := range defaultSub {
(*sub)[key] = value
Expand Down Expand Up @@ -100,3 +100,26 @@ var trSub = map[rune]string{
'ç': "c",
'Ç': "C",
}

var kkSub = map[rune]string{
'&': "jane",
'ә': "a",
Comment on lines +105 to +106
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You missed mapping @ symbol.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

People don't use @ at Kazakh, that's why I used default @=>`` ( empty )

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is strange for me. What about writing email address in text (like [email protected])?

Personally I would prefer handling @ but will merge it as is for now, and fix if someone complain.

'ғ': "g",
'һ': "h",
'і': "i",
'ң': "n",
'ө': "o",
'қ': "q",
'ұ': "u",
'ү': "u",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little confused. Do we really need all of them here? As far as I checked https://github.com/rainycape/unidecode/blob/master/table.txt almost all of them are already handled correctly.

The only difference I see you change қ to q and unidecode library is changing it to k. We can use your version here if it's better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modern translation қ => q, so its correct

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without this additional subtitution ң converted to n- (and others )

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you are right. Don't know why I mentally removed - from them.


'Ә': "A",
'Ғ': "G",
'Һ': "H",
'І': "I",
'Ң': "N",
'Ө': "O",
'Қ': "Q",
'Ұ': "U",
'Ү': "U",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ups, they are ordered here by commenting order and not simply from top. This refer to comment that most of them are already handled correctly by unidecode library.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without this additional subtitution ң converted to n- (and others )

}
2 changes: 2 additions & 0 deletions slug.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
gumeniukcom marked this conversation as resolved.
Show resolved Hide resolved
default: // fallback to "en" if lang not found
slug = SubstituteRune(slug, enSub)
}
Expand Down
5 changes: 5 additions & 0 deletions slug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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.
Expand All @@ -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},
gumeniukcom marked this conversation as resolved.
Show resolved Hide resolved
}

for index, smlt := range testCases {
Expand All @@ -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"
}
Expand Down