Giter VIP home page Giter VIP logo

i18n's People

Contributors

6543 avatar chadoe avatar tamalsaha avatar unknwon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

i18n's Issues

undefined error on go get

../../macaron-contrib/i18n/i18n.go:94: undefined: macaron.Config
when running go get github.com/macaron-contrib/i18n

Matching preferred against supported languages

As brought up by gogs/gogs/issues/2958

Currently, go-macaron/i18n only does a string match for supported languages from the "Accept-Language" http header.

// 3. Get language information from 'Accept-Language'.
if len(lang) == 0 {
    al := ctx.Req.Header.Get("Accept-Language")
    if len(al) > 4 {
        al = al[:5] // Only compare first 5 letters.
        if i18n.IsExist(al) {
            lang = al
        }
    }
}

This is a problem when browsers send different language tags for the same language or matching similar languages. The good thing is that golang.org/x/text/language implements this feature.

We should use language.ParseAcceptLanguage to extract the language tags, and language.Matcher to select the best language to use.

An alternative is to add MatchAcceptLanguage(s string) (string, err) to Unknwon/i18n using the above so the calling code will just be:

// 3. Get language information from 'Accept-Language'.
if len(lang) == 0 {
    al, err := i18n.MatchAcceptLanguage(ctx.Req.Header.Get("Accept-Language"))
    if err == nil {
        lang = al
    }
}

I can do a pull request if you like this idea. The only down side is all the casting between string and language.Tag has a code smell.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.