Skip to content

Conversation

@mh-cbon
Copy link
Contributor

@mh-cbon mh-cbon commented Oct 16, 2016

$ go test ./... -bench=.
PASS
ok      github.com/nicksnyder/go-i18n/goi18n    0.007s
PASS
ok      github.com/nicksnyder/go-i18n/i18n  0.004s
BenchmarkTranslateNonPluralWithMap-4                 1000000          3343 ns/op
BenchmarkTranslateNonPluralWithStruct-4               500000          4071 ns/op
BenchmarkTranslateNonPluralWithStructPointer-4        500000          5344 ns/op
BenchmarkTranslatePluralWithMap-4                    1000000          4363 ns/op
BenchmarkTranslatePluralWithMapAndCountField-4        500000          3845 ns/op
BenchmarkTranslatePluralWithStruct-4                  300000          5993 ns/op
BenchmarkTranslatePluralWithStructPointer-4           300000          4641 ns/op
PASS
ok      github.com/nicksnyder/go-i18n/i18n/bundle   17.785s
BenchmarkNewOperand-4       ^[[A 2000000           818 ns/op
PASS
ok      github.com/nicksnyder/go-i18n/i18n/language 2.497s
?       github.com/nicksnyder/go-i18n/i18n/language/codegen [no test files]
BenchmarkExecuteNilTemplate-4           300000000            3.75 ns/op
BenchmarkExecuteHelloWorldTemplate-4    500000000            3.74 ns/op
BenchmarkExecuteHelloNameTemplate-4      1000000          1934 ns/op
BenchmarkSprintf-4                      10000000           397 ns/op
PASS
ok      github.com/nicksnyder/go-i18n/i18n/translation  9.950s

$ go test ./...
ok      github.com/nicksnyder/go-i18n/goi18n    0.016s
ok      github.com/nicksnyder/go-i18n/i18n  0.004s
ok      github.com/nicksnyder/go-i18n/i18n/bundle   0.004s
ok      github.com/nicksnyder/go-i18n/i18n/language 0.014s
?       github.com/nicksnyder/go-i18n/i18n/language/codegen [no test files]
ok      github.com/nicksnyder/go-i18n/i18n/translation  0.008s

One q i have, now there s a strconv.Atoi if Count field value is a string.

Which may return an error, see this

I m unsure if it should panic, for instance it just ignores the parameter, thus, the template rendering operation will probably fails, which, if i m right, should display the translation id, without any warning.

The "without a warning" bother me, but panicking bother me too.

:- /

if c, ok := dataMap["Count"]; ok {
if cStr, ok := c.(string); ok {
var err error
count, err = strconv.Atoi(cStr)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this more complicated than the original PR (#49)?

You don't need to convert the string to a number because the library already handles this conversion later on this line:

p, _ := lang.Plural(count)


fmt.Println(T("your_unread_email_count", map[string]interface{}{"Count": 0}))
fmt.Println(T("your_unread_email_count", map[string]interface{}{"Count": "1"}))
fmt.Println(T("your_unread_email_count", map[string]interface{}{"Count": "3.14"}))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add tests for "person_unread_email_count_timeframe" to show that it works with other template data?

It would also be nice to have a test for what happens if both are provided (a count parameter and a template with a Count variable).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np, both are added.

i18n/i18n.go Outdated
//
// If translationID is a plural form, then the first variadic argument must be an integer type
// If translationID is a plural form, the function accepts two parameter signatures
// - T(count int, data struct{})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be slightly more readable as a numbered list (i.e. 1. here instead of -).

@nicksnyder
Copy link
Owner

The library is designed not to panic, but if consumers of the library wish to panic or do some error handling, then they can wrap the T function and detect when the returned translation is equal to the translation id.

@mh-cbon
Copy link
Contributor Author

mh-cbon commented Oct 17, 2016

ok thanks, anyway the changes removed that err, so the question does not matter anymore

data = dataMap
}
}
{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be an else right?

if count != nil {
    // current logic
} else {
    dataMap := toMap(data)
    if c, ok := dataMap["Count"]; ok {
        count = c
    }
}

@mh-cbon
Copy link
Contributor Author

mh-cbon commented Oct 18, 2016

we got an else ! BTW, i just noticed the travis file may need a little update for 1.6.

@nicksnyder nicksnyder merged commit 1c9e017 into nicksnyder:master Oct 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants