开发者

How to handle i18n in Go?

开发者 https://www.devze.com 2023-04-08 02:58 出处:网络
I searched on web but I didn\'t find anything related to i18n and Go. I wish 开发者_StackOverflow社区to use Go for develop web sites. What is the best way to handle internationalization?go-i18n has s

I searched on web but I didn't find anything related to i18n and Go.

I wish 开发者_StackOverflow社区to use Go for develop web sites. What is the best way to handle internationalization?


go-i18n has some nice features:

  • Implements CLDR plural rules.
  • Uses text/template for strings with variables.
  • Translation files are simple JSON.


Packages roadmap

Comprehensive support for international text.
Support for international dates, times, etc.
Support for multilingual messages.

As you can see from the Go Roadmap, Go doesn't provide full i18n support yet.


The new template package allows you to at add a function to template's function map, that would transform the given string to a localized version. What's going on underneath would be up to you for now, as the language choice could be based on headers sent by the browser.

That's a very basic use case for adding localized messages in a web app, for one.

Can't wait for the proper support for internationalization, local date and time formats.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号