Add race conditions tests. Fix races.

This commit is contained in:
Leonel Quinteros
2016-06-24 17:45:12 -03:00
parent 6e728a3df5
commit d6f4cbb2d5
5 changed files with 187 additions and 0 deletions

8
po.go
View File

@@ -186,6 +186,10 @@ func (po *Po) Parse(str string) {
// Get retrieves the corresponding translation for the given string.
// Supports optional parameters (vars... interface{}) to be inserted on the formatted string using the fmt.Printf syntax.
func (po *Po) Get(str string, vars ...interface{}) string {
// Sync read
po.RLock()
defer po.RUnlock()
if po.translations != nil {
if _, ok := po.translations[str]; ok {
return fmt.Sprintf(po.translations[str].get(), vars...)
@@ -200,6 +204,10 @@ func (po *Po) Get(str string, vars ...interface{}) string {
// If n == 0, usually the singular form of the string is returned as defined in the PO file.
// Supports optional parameters (vars... interface{}) to be inserted on the formatted string using the fmt.Printf syntax.
func (po *Po) GetN(str, plural string, n int, vars ...interface{}) string {
// Sync read
po.RLock()
defer po.RUnlock()
if po.translations != nil {
if _, ok := po.translations[str]; ok {
return fmt.Sprintf(po.translations[str].getN(n), vars...)