Skip to content

Commit

Permalink
Merge branch 'master' into add-romanian
Browse files Browse the repository at this point in the history
  • Loading branch information
matrixik authored Sep 27, 2022
2 parents f551ffd + d33d626 commit f9a3462
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 20 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/rebase.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
fetch-depth: 0

- name: Automatic Rebase
uses: cirrus-actions/[email protected]
uses: cirrus-actions/[email protected]
with:
autosquash: ${{ contains(github.event.comment.body, '/autosquash') || contains(github.event.comment.body, '/rebase-autosquash') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22 changes: 8 additions & 14 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [1.16.x, 1.x]
go-version: [1.18.x, 1.x]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 1
- uses: WillAbides/setup-go-faster@v1
with:
go-version: ${{ matrix.go-version }}

- uses: actions/cache@v2
- uses: actions/cache@v3
with:
# In order:
# * Module download cache
Expand All @@ -48,29 +48,23 @@ jobs:
go test -race -coverprofile=coverage.out -covermode=atomic
go tool cover -func=coverage.out
- uses: codecov/codecov-action@v2
- uses: codecov/codecov-action@v3
with:
files: ./coverage.out

lint:
name: "Run static analysis"
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 1
- uses: WillAbides/setup-go-faster@v1
with:
go-version: "1.x"

- run: "GO111MODULE=on go get honnef.co/go/tools/cmd/staticcheck"
- run: "go vet ./..."

- uses: actions/cache@v2
- uses: dominikh/staticcheck-action@v1
with:
path: ~/.cache/staticcheck
key: staticcheck-${{ github.sha }}
restore-keys: |
staticcheck-
- run: "go vet ./..."
- run: "$(go env GOPATH)/bin/staticcheck ./..."
version: "2022.1.3"
70 changes: 70 additions & 0 deletions languages_substitution.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ func init() {
// TODO: Find better way so all langs are merged automatically and better
// tested.
for _, sub := range []*map[rune]string{
&bgSub,
&csSub,
&deSub,
&enSub,
Expand All @@ -19,6 +20,7 @@ func init() {
&grSub,
&huSub,
&idSub,
&itSub,
&kkSub,
&nbSub,
&nlSub,
Expand Down Expand Up @@ -123,6 +125,11 @@ var idSub = map[rune]string{
'&': "dan",
}

var itSub = map[rune]string{
'&': "e",
'@': "chiocciola",
}

var kkSub = map[rune]string{
'&': "jane",
'ә': "a",
Expand Down Expand Up @@ -204,3 +211,66 @@ var trSub = map[rune]string{
'ç': "c",
'Ç': "C",
}

var bgSub = map[rune]string{
'А': "A",
'Б': "B",
'В': "V",
'Г': "G",
'Д': "D",
'Е': "E",
'Ж': "Zh",
'З': "Z",
'И': "I",
'Й': "Y",
'К': "K",
'Л': "L",
'М': "M",
'Н': "N",
'О': "O",
'П': "P",
'Р': "R",
'С': "S",
'Т': "T",
'У': "U",
'Ф': "F",
'Х': "H",
'Ц': "Ts",
'Ч': "Ch",
'Ш': "Sh",
'Щ': "Sh",
'Ъ': "A",
'Ь': "Y",
'Ю': "Yu",
'Я': "Ya",
'а': "a",
'б': "b",
'в': "v",
'г': "g",
'д': "d",
'е': "e",
'ж': "zh",
'з': "z",
'и': "i",
'й': "y",
'к': "k",
'л': "l",
'м': "m",
'н': "n",
'о': "o",
'п': "p",
'р': "r",
'с': "s",
'т': "t",
'у': "u",
'ф': "f",
'х': "h",
'ц': "ts",
'ч': "ch",
'ш': "sh",
'щ': "sht",
'ъ': "a",
'ь': "y",
'ю': "yu",
'я': "ya",
}
4 changes: 4 additions & 0 deletions slug.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ func MakeLang(s string, lang string) (slug string) {
// Process string with selected substitution language.
// Catch ISO 3166-1, ISO 639-1:2002 and ISO 639-3:2007.
switch strings.ToLower(lang) {
case "bg", "bgr":
slug = SubstituteRune(slug, bgSub)
case "cs", "ces":
slug = SubstituteRune(slug, csSub)
case "de", "deu":
Expand All @@ -75,6 +77,8 @@ func MakeLang(s string, lang string) (slug string) {
slug = SubstituteRune(slug, huSub)
case "id", "idn", "ind":
slug = SubstituteRune(slug, idSub)
case "it", "ita":
slug = SubstituteRune(slug, itSub)
case "kz", "kk", "kaz":
slug = SubstituteRune(slug, kkSub)
case "nb", "nob":
Expand Down
18 changes: 13 additions & 5 deletions slug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestSlugMake(t *testing.T) {
{"jaja---lol-méméméoo--a", "jaja-lol-mememeoo-a"},
{"影師", "ying-shi"},
{"Đanković & Kožušček", "dankovic-and-kozuscek"},
{"ĂăÂâÎîȘșȚț", "aaaaiisstt"},
{"ĂăÂâÎîȘșȚț", "aaaaiisstt"},
}

for index, st := range testCases {
Expand All @@ -74,6 +74,8 @@ func TestSlugMakeLang(t *testing.T) {
want string
lowercase bool
}{
{"bg", "АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЬЮЯабвгдежзийклмнопрстуфхцчшщъьюя", "abvgdezhziyklmnoprstufhtschshshayyuyaabvgdezhziyklmnoprstufhtschshshtayyuya", true},
{"bg", "АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЬЮЯабвгдежзийклмнопрстуфхцчшщъьюя", "ABVGDEZhZIYKLMNOPRSTUFHTsChShShAYYuYaabvgdezhziyklmnoprstufhtschshshtayyuya", false},
{"cs", "ěščřžýáíéúůóňťĚŠČŘŽÝÁÍÉÚŮÓŇŤ", "escrzyaieuuontescrzyaieuuont", true},
{"cs", "ěščřžýáíéúůóňťĚŠČŘŽÝÁÍÉÚŮÓŇŤ", "escrzyaieuuontESCRZYAIEUUONT", false},
{"ces", "ěščřžýáíéúůóňťĚŠČŘŽÝÁÍÉÚŮÓŇŤ", "escrzyaieuuontescrzyaieuuont", true},
Expand All @@ -91,13 +93,15 @@ func TestSlugMakeLang(t *testing.T) {
{"hu", "SzÉlÜtÖtt ŰrÚjsÁgírÓnŐ", "SzElUtOtt-UrUjsAgirOnO", false},
{"Ell", "ϊχώΩϋ", "ixwwu", true},
{"Ell", "ϊχώΩϋ", "ixwwu", false},
{"tr", "şüöğıçŞÜÖİĞÇ", "suogicsuoigc", true},
{"tr", "şüöğıçŞÜÖİĞÇ", "suogicSUOIGC", false},
{"kk", "әғһіңөқұүӘҒҺІҢӨҚҰҮ", "aghinoquuaghinoquu", true},
{"kk", "әғһіңөқұүӘҒҺІҢӨҚҰҮ", "aghinoquuAGHINOQUU", false},
{"ro", "ĂăÂăÎîȘșȚț", "aaaaiisstt", true},
{"ro", "ĂăÂăÎîȘșȚț", "AaAaIiSsTt", false},
{"ro", "ĂăÂăÎîȘșȚț", "aaaaiisstt", true},
{"ro", "ĂăÂăÎîȘșȚț", "AaAaIiSsTt", false},
{"tr", "şüöğıçŞÜÖİĞÇ", "suogicsuoigc", true},
{"tr", "şüöğıçŞÜÖİĞÇ", "suogicSUOIGC", false},

// & fun.
{"bg", "Това и онова", "tova-i-onova", true},
{"cs", "Toto & Tamto", "toto-a-tamto", true},
{"cs", "Toto & Tamto", "Toto-a-Tamto", false},
{"cs", "Toto @ Tamto", "toto-zavinac-tamto", true},
Expand All @@ -114,6 +118,8 @@ func TestSlugMakeLang(t *testing.T) {
{"fr", "This @ that", "this-arobase-that", true},
{"gr", "This & that", "this-kai-that", true},
{"id", "This & that", "this-dan-that", true},
{"it", "This & that", "this-e-that", true},
{"it", "This @ that", "this-chiocciola-that", true},
{"ell", "This & that", "this-kai-that", true},
{"Ell", "This & that", "this-kai-that", true},
{"kk", "This & that", "this-jane-that", true},
Expand All @@ -135,8 +141,10 @@ func TestSlugMakeLang(t *testing.T) {
{"sl", "đanković & Kožušček", "dzankovic-in-kozuscek", true},
{"sl", "ĐankoVIĆ & KOŽUŠČEK", "DZankoVIC-in-KOZUSCEK", false},
{"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.
{"bg", "1\"2'3’4‒5–6—7―8", "1234-5-6-7-8", true},
{"cs", "1\"2'3’4‒5–6—7―8", "1234-5-6-7-8", true},
{"de", "1\"2'3’4‒5–6—7―8", "1234-5-6-7-8", true},
{"en", "1\"2'3’4‒5–6—7―8", "1234-5-6-7-8", true},
Expand Down

0 comments on commit f9a3462

Please sign in to comment.