🏷️ Replaced Language property in File domain
This commit is contained in:
parent
c83a86119e
commit
9cdb470ada
|
@ -4,12 +4,10 @@ import (
|
|||
"crypto/md5"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
type File struct {
|
||||
language language.Tag
|
||||
Language Language
|
||||
baseFileName string
|
||||
contentBaseName string
|
||||
dir string
|
||||
|
@ -23,7 +21,7 @@ type File struct {
|
|||
|
||||
func NewFile(path string) File {
|
||||
out := File{
|
||||
language: language.Tag{},
|
||||
Language: LanguageUnd,
|
||||
baseFileName: "",
|
||||
contentBaseName: "",
|
||||
dir: filepath.Dir(path) + "/",
|
||||
|
@ -38,7 +36,7 @@ func NewFile(path string) File {
|
|||
out.baseFileName = strings.TrimSuffix(out.logicalName, filepath.Ext(out.logicalName))
|
||||
|
||||
parts := strings.Split(out.baseFileName, ".")
|
||||
out.language = language.Make(parts[len(parts)-1])
|
||||
out.Language = NewLanguage(parts[len(parts)-1])
|
||||
out.translationBaseName = strings.Join(parts[:len(parts)-1], ".")
|
||||
out.contentBaseName = out.translationBaseName
|
||||
|
||||
|
@ -79,12 +77,6 @@ func (f File) Filename() string {
|
|||
return f.filename
|
||||
}
|
||||
|
||||
// Language returns language.Tag of current file based on his suffix before
|
||||
// extention.
|
||||
func (f File) Language() language.Tag {
|
||||
return f.language
|
||||
}
|
||||
|
||||
func (f File) LogicalName() string {
|
||||
return f.logicalName
|
||||
}
|
||||
|
|
|
@ -4,8 +4,6 @@ import (
|
|||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/text/language"
|
||||
|
||||
"source.toby3d.me/toby3d/home/internal/domain"
|
||||
)
|
||||
|
||||
|
@ -106,7 +104,7 @@ func TestFile_Ext(t *testing.T) {
|
|||
func TestFile_Language(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var expect language.Tag = language.English
|
||||
var expect domain.Language = domain.NewLanguage("en")
|
||||
|
||||
for name, input := range map[string]string{
|
||||
"regular": testRegularFile,
|
||||
|
@ -118,7 +116,7 @@ func TestFile_Language(t *testing.T) {
|
|||
t.Run(name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if actual := domain.NewFile(input).Language(); actual != expect {
|
||||
if actual := domain.NewFile(input).Language; actual != expect {
|
||||
t.Errorf("Language() = '%s', want '%s'", actual, expect)
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue