Skip to content

Commit

Permalink
Add parse functions for Language type
Browse files Browse the repository at this point in the history
  • Loading branch information
KillerX committed Nov 20, 2024
1 parent ac0ddd6 commit 556f197
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions language_parser.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package bccmflows

import "github.com/ansel1/merry/v2"

var LanguageParseError = merry.Sentinel("uanable to parse language code")

func ParseLanguageCode(langCode string) (Language, error) {

if lang, ok := LanguagesByISO[langCode]; ok {
return lang, nil
}

if lang, ok := LanguagesByISOTwoLetter[langCode]; ok {
return lang, nil
}

return Language{}, merry.Wrap(LanguageParseError)
}

func MustParseLanguageCode(langCode string) Language {
l, err := ParseLanguageCode(langCode)
if err != nil {
panic(err)
}

return l
}

0 comments on commit 556f197

Please sign in to comment.