Этот коммит содержится в:
Christopher Speller
2017-05-17 16:51:25 -04:00
коммит произвёл GitHub
родитель cd23b8139a
Коммит d103ed6ca9
1001 изменённых файлов: 191052 добавлений и 5192 удалений

4
vendor/github.com/nicksnyder/go-i18n/goi18n/testdata/en-us.flat.yaml сгенерированный поставляемый
Просмотреть файл

@@ -1,3 +1,7 @@
# Comment
# Comment
program_greeting:
other: "Hello world"

5
vendor/github.com/nicksnyder/go-i18n/goi18n/testdata/en-us.yaml сгенерированный поставляемый
Просмотреть файл

@@ -1,3 +1,8 @@
# Comment
# Comment
- id: program_greeting
translation: "Hello world"

39
vendor/github.com/nicksnyder/go-i18n/i18n/bundle/bundle.go сгенерированный поставляемый
Просмотреть файл

@@ -9,6 +9,7 @@ import (
"path/filepath"
"reflect"
"sync"
"unicode"
"github.com/nicksnyder/go-i18n/i18n/language"
"github.com/nicksnyder/go-i18n/i18n/translation"
@@ -86,8 +87,8 @@ func parseTranslations(filename string, buf []byte) ([]translation.Translation,
ext := filepath.Ext(filename)
// `github.com/pelletier/go-toml` has an Unmarshal function,
// that can't unmarshal to maps, so we should parse TOML format separately.
// `github.com/pelletier/go-toml` lacks an Unmarshal function,
// so we should parse TOML separately.
if ext == ".toml" {
tree, err := toml.LoadReader(bytes.NewReader(buf))
if err != nil {
@@ -119,11 +120,39 @@ func parseTranslations(filename string, buf []byte) ([]translation.Translation,
}
func isStandardFormat(ext string, buf []byte) bool {
buf = deleteLeadingComments(ext, buf)
firstRune := rune(buf[0])
if (ext == ".json" && firstRune == '[') || (ext == ".yaml" && firstRune == '-') {
return true
return (ext == ".json" && firstRune == '[') || (ext == ".yaml" && firstRune == '-')
}
// deleteLeadingComments deletes leading newlines and comments in buf.
// It only works for ext == ".yaml".
func deleteLeadingComments(ext string, buf []byte) []byte {
if ext != ".yaml" {
return buf
}
return false
for {
buf = bytes.TrimLeftFunc(buf, unicode.IsSpace)
if buf[0] == '#' {
buf = deleteLine(buf)
} else {
break
}
}
return buf
}
func deleteLine(buf []byte) []byte {
index := bytes.IndexRune(buf, '\n')
if index == -1 { // If there is only one line without newline ...
return nil // ... delete it and return nothing.
}
if index == len(buf)-1 { // If there is only one line with newline ...
return nil // ... do the same as above.
}
return buf[index+1:]
}
// unmarshal finds an appropriate unmarshal function for ext