Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broke Compatibility #13

Closed
ardan-bkennedy opened this issue Jul 9, 2014 · 1 comment
Closed

Broke Compatibility #13

ardan-bkennedy opened this issue Jul 9, 2014 · 1 comment

Comments

@ardan-bkennedy
Copy link

Hi Nick, Found out today my vendored version is not compatible with the new version. Specifically this function of mine does not work anymore because the locale package is gone.

My Call to AddTranslation:
i18n.AddTranslation(locale.MustNew(userLocale), tran)

What is the new mechanism for this. I spent a handful of minutes looking but found nothing obvious.

Thanks

// LoadJSON takes a json document of translations and manually
// loads them into the system
func LoadJSON(userLocale string, translationDocument string) error {
tracelog.Startedf("localize", "LoadJSON", "UserLocale[%s] Length[%d]", userLocale, len(translationDocument))

tranDocuments := []map[string]interface{}{}
err := json.Unmarshal([]byte(translationDocument), &tranDocuments)
if err != nil {
    tracelog.CompletedErrorf(err, "localize", "LoadJSON", "**************>")
    return err
}

for _, tranDocument := range tranDocuments {
    tran, err := translation.NewTranslation(tranDocument)
    if err != nil {
        tracelog.CompletedError(err, "localize", "LoadJSON")
        return err
    }

    i18n.AddTranslation(locale.MustNew(userLocale), tran)
}

tracelog.Completed("localize", "LoadJSON")
return nil

}

@nicksnyder
Copy link
Owner

Sorry for the inconvenience of broken compatibility. I needed to modify some of the APIs to extend the flexibility of language parsing. language.Parse(userLocale) replaces locale.MustNew(userLocale).

The only difference is that it returns all languages that it can parse from the string. It is up to you to decide what to do if it finds 0 or more than 1 languages (probably an error case).

I will mark this as closed, but feel free to reopen if you have additional questions.

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

No branches or pull requests

2 participants