From ed8e63c26880c630bd1b03d62d46ed076f7f5afc Mon Sep 17 00:00:00 2001 From: bytedream Date: Sun, 8 May 2022 11:06:37 +0200 Subject: [PATCH] Fix locale panic (#29) --- cmd/crunchyroll-go/cmd/utils.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cmd/crunchyroll-go/cmd/utils.go b/cmd/crunchyroll-go/cmd/utils.go index 136fe28..29a48f7 100644 --- a/cmd/crunchyroll-go/cmd/utils.go +++ b/cmd/crunchyroll-go/cmd/utils.go @@ -33,9 +33,13 @@ var urlFilter = regexp.MustCompile(`(S(\d+))?(E(\d+))?((-)(S(\d+))?(E(\d+))?)?(, func systemLocale(verbose bool) crunchyroll.LOCALE { if runtime.GOOS != "windows" { if lang, ok := os.LookupEnv("LANG"); ok { - prefix := strings.Split(lang, "_")[0] - suffix := strings.Split(strings.Split(lang, ".")[0], "_")[1] - l := crunchyroll.LOCALE(fmt.Sprintf("%s-%s", prefix, suffix)) + var l crunchyroll.LOCALE + if preSuffix := strings.Split(strings.Split(lang, ".")[0], "_"); len(preSuffix) == 1 { + l = crunchyroll.LOCALE(preSuffix[0]) + } else { + prefix := strings.Split(lang, "_")[0] + l = crunchyroll.LOCALE(fmt.Sprintf("%s-%s", prefix, preSuffix[1])) + } if !utils.ValidateLocale(l) { if verbose { out.Err("%s is not a supported locale, using %s as fallback", l, crunchyroll.US)