# Web Form Validation And Localization In Go

DevFeed: [Web Form Validation And Localization In Go](<https://devfeed.tech/articles/web-form-validation-and-localization-in-go-22098.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2014/03/web-form-validation-and-localization-in.html>)

Published: 2014-03-07T00:00:00Z

Content type: tutorial

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [Go Language](<https://devfeed.tech/topics/go-language.md>), [Internationalization (i18n)](<https://devfeed.tech/topics/i18n.md>), [Localization (l10n)](<https://devfeed.tech/topics/localization.md>), [JSON](<https://devfeed.tech/topics/json.md>)

Tags: [ardan-labs](<https://devfeed.tech/tags/ardan-labs.md>), [blog](<https://devfeed.tech/tags/blog.md>), [go](<https://devfeed.tech/tags/go.md>), [go-programming](<https://devfeed.tech/tags/go-programming.md>), [golang](<https://devfeed.tech/tags/golang.md>), [json](<https://devfeed.tech/tags/json.md>), [languages](<https://devfeed.tech/tags/languages.md>), [programming](<https://devfeed.tech/tags/programming.md>), [translation](<https://devfeed.tech/tags/translation.md>), [validation](<https://devfeed.tech/tags/validation.md>), [web](<https://devfeed.tech/tags/web.md>)

## AI overview

This tutorial explains how to integrate go-i18n into a Go web service built with the Beego sample app. It covers localized validation messages, locale-specific pluralization, variable substitution, and storing message data as JSON strings rather than external files.

## Source excerpt

Introduction As I improve my knowledge and framework for a Go based web service I am building, I continue to go back and enhance my Beego Sample App. Something I just added recently was providing localized messages for validation errors. I was fortunate to find Nick Snyder's go-i18n package. Nick's package made it easy to support multiple languages for the Go web service I am writing. Abstracting go-i18n The go-i18n package is simple to use and you can use it to read files or strings that contain all the messages you want to localize. It has some nice features including variable substitution and support for handling plurals for each individual locale. Nick has documentation for his package, so I am going to show you how I abstracted and integrated go-i18n into the Beego sample app. I decided I didn't want to use files to store the messages, but create raw string literal variables. The less I had to worry about managing external resources the better. With that being said, I built a simple package that abstracted the support I needed. Luckily go-i18n supports passing in a string that can contain the JSON document with the message data: I am just using simple messages right now, but as you can see, the variable En_US is defined and assigned a JSON document with the messages I need localized. The go-i18n package also lets you define messages like this: In this sample, the translation has one message for the singular case and one for the plural case. There is also support for using variable substitution thanks to template support. Here is the localize package that provides support for the web service: The Init function creates the default locale for the application. Currently the Beego Sample App only supports English for the United States. Eventually, we can add cases for the other locales. Obviously this can all be done through configuration in the future. The Init function uses the LoadJSON function to load the go-i18n datastore with the internal messages for the defa