Improve sync method. Improve docs.

This commit is contained in:
Leonel Quinteros
2016-06-23 12:54:38 -03:00
parent 569d905178
commit 64c6ac19d9
2 changed files with 39 additions and 3 deletions

9
po.go
View File

@@ -75,11 +75,10 @@ func (po *Po) ParseFile(f string) {
// Parse loads the translations specified in the provided string (str)
func (po *Po) Parse(str string) {
po.Lock()
defer po.Unlock()
if po.translations == nil {
po.Lock()
po.translations = make(map[string]*translation)
po.Unlock()
}
lines := strings.Split(str, "\n")
@@ -103,7 +102,9 @@ func (po *Po) Parse(str string) {
// Buffer msgid and continue
if strings.HasPrefix(l, "msgid") && !strings.HasPrefix(l, "msgid_plural") {
// Save current translation buffer.
po.Lock()
po.translations[tr.id] = tr
po.Unlock()
// Flush buffer
tr = newTranslation()
@@ -156,7 +157,9 @@ func (po *Po) Parse(str string) {
// Save last translation buffer.
if tr.id != "" {
po.Lock()
po.translations[tr.id] = tr
po.Unlock()
}
}