Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
756045ab5e | ||
|
|
2bb9254f26 | ||
|
|
88952938dc |
@@ -1,5 +1,5 @@
|
||||
[](https://github.com/leonelquinteros/gotext)
|
||||
[](LICENSE)
|
||||
[](https://badge.fury.io/gh/leonelquinteros%2Fgotext)
|
||||
[](https://godoc.org/github.com/leonelquinteros/gotext)
|
||||
[](https://travis-ci.org/leonelquinteros/gotext)
|
||||
[](https://codecov.io/gh/leonelquinteros/gotext)
|
||||
@@ -9,8 +9,6 @@
|
||||
|
||||
[GNU gettext utilities](https://www.gnu.org/software/gettext) for Go.
|
||||
|
||||
Version: [v1.1.1](https://github.com/leonelquinteros/gotext/releases/tag/v1.1.1)
|
||||
|
||||
|
||||
# Features
|
||||
|
||||
|
||||
4
po.go
4
po.go
@@ -29,8 +29,10 @@ func newTranslation() *translation {
|
||||
func (t *translation) get() string {
|
||||
// Look for translation index 0
|
||||
if _, ok := t.trs[0]; ok {
|
||||
if t.trs[0] != "" {
|
||||
return t.trs[0]
|
||||
}
|
||||
}
|
||||
|
||||
// Return unstranlated id by default
|
||||
return t.id
|
||||
@@ -39,8 +41,10 @@ func (t *translation) get() string {
|
||||
func (t *translation) getN(n int) string {
|
||||
// Look for translation index
|
||||
if _, ok := t.trs[n]; ok {
|
||||
if t.trs[n] != "" {
|
||||
return t.trs[n]
|
||||
}
|
||||
}
|
||||
|
||||
// Return unstranlated plural by default
|
||||
return t.pluralID
|
||||
|
||||
34
po_test.go
34
po_test.go
@@ -69,8 +69,17 @@ msgctxt "Ctx"
|
||||
msgid "Some random in a context"
|
||||
msgstr "Some random translation in a context"
|
||||
|
||||
msgid "Empty translation"
|
||||
msgstr ""
|
||||
|
||||
msgid "Empty plural form singular"
|
||||
msgid_plural "Empty plural form"
|
||||
msgstr[0] "Singular translated"
|
||||
msgstr[1] "
|
||||
|
||||
msgid "More"
|
||||
msgstr "More translation"
|
||||
"
|
||||
`
|
||||
|
||||
// Write PO content to file
|
||||
@@ -145,8 +154,8 @@ msgstr "More translation"
|
||||
|
||||
// Test syntax error parsed translations
|
||||
tr = po.Get("This one has invalid syntax translations")
|
||||
if tr != "" {
|
||||
t.Errorf("Expected '' but got '%s'", tr)
|
||||
if tr != "This one has invalid syntax translations" {
|
||||
t.Errorf("Expected 'This one has invalid syntax translations' but got '%s'", tr)
|
||||
}
|
||||
|
||||
tr = po.GetN("This one has invalid syntax translations", "This are tests", 4)
|
||||
@@ -177,6 +186,27 @@ msgstr "More translation"
|
||||
t.Errorf("Expected 'Original' but got '%s'", tr)
|
||||
}
|
||||
|
||||
// Test empty translation strings
|
||||
tr = po.Get("Empty translation")
|
||||
if tr != "Empty translation" {
|
||||
t.Errorf("Expected 'Empty translation' but got '%s'", tr)
|
||||
}
|
||||
|
||||
tr = po.Get("Empty plural form singular")
|
||||
if tr != "Singular translated" {
|
||||
t.Errorf("Expected 'Singular translated' but got '%s'", tr)
|
||||
}
|
||||
|
||||
tr = po.GetN("Empty plural form singular", "Empty plural form", 1)
|
||||
if tr != "Singular translated" {
|
||||
t.Errorf("Expected 'Singular translated' but got '%s'", tr)
|
||||
}
|
||||
|
||||
tr = po.GetN("Empty plural form singular", "Empty plural form", 2)
|
||||
if tr != "Empty plural form" {
|
||||
t.Errorf("Expected 'Empty plural form' but got '%s'", tr)
|
||||
}
|
||||
|
||||
// Test last translation
|
||||
tr = po.Get("More")
|
||||
if tr != "More translation" {
|
||||
|
||||
Reference in New Issue
Block a user