Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
github.com/klauspost/lctime
Finally, simple, familiar, locale-based datetime formatting.
go get -u github.com/klauspost/lctime
// Default locale is based on env vars or en_US if none are set.
fmt.Println(lctime.Strftime("%c", time.Now()))
// prints: Mon 14 Dec 2015 10:31:56 PM PST
lctime.SetLocale("es_MX")
fmt.Println(lctime.Strftime("%c", time.Now()))
// prints: lun 14 dic 2015 22:31:56 PST
This is very easy if your application only has to translate to a single language.
To do translation to multiple languages without having collisions, you can use
the StrftimeLoc
function. It allows you to specify a locale along your time to be translated.
t := time.Date(2015, 12, 25, 3, 2, 1, 0, time.UTC)
txt, err := StrftimeLoc("es_MX", "%A, %d de %B de %Y", t)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(txt)
// Prints viernes, 25 de diciembre de 2015
If you need to do several translations or need to pass your localizer as a
parameter, you can use the
NewLocalizer
function. It allows you to localize several strings to the same language without
having to specify it every time.
t := time.Date(2015, 12, 25, 3, 2, 1, 0, time.UTC)
l, err := NewLocalizer("da_DK")
if err != nil {
fmt.Println(err)
return
}
fmt.Println(l.Strftime("%A den %d. %B %Y", t))
// Prints: fredag den 25. december 2015
Go's standard library time
is fine most of the time. However, it's currently
impossible for the Go standard library to format dates based on a user's locale
or langauge setting. Unfortunately, that means code like this, doesn't work.
d := time.Date(2015, 12, 25, 3, 2, 1, 0, time.UTC)
fmt.Println(d.Format("lunes, 02 de enero de 2006"))
// got: lunes, 25 de enero de 2015
// want: viernes, 25 de diciembre de 2015
More importantly, it also means that non-English speakers will either be stuck with purely numeric dates or dates in a language they don't prefer.
lctime
brings the familiar setlocale
and strftime
functions found in other
programming languages like C, Python, or PHP. The formats and translations used
for this package are loosely based on glibc locale files, with close to 300
locales.
Locale data is just Go code, generated by go-bindata. This means you don't
have to worry about shipping anything extra. Just import and use lctime
like
any other package and go build
like normal. Everything will just work.
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.