go-macaron / i18n Goto Github PK
View Code? Open in Web Editor NEWPackage i18n provides an Internationalization and Localization middleware for Macaron applications
License: Apache License 2.0
Package i18n provides an Internationalization and Localization middleware for Macaron applications
License: Apache License 2.0
Hi,
I ran into a panic while the i18n
library tried to open a file that diddn't exist on my filesystem.
Some sort of graceful error handling, replacing the call to panic (https://github.com/go-macaron/i18n/blob/master/i18n.go#L57), would be nice.
If I'm not wrong this would break the API.
../../macaron-contrib/i18n/i18n.go:94: undefined: macaron.Config
when running go get github.com/macaron-contrib/i18n
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.