Codemi Blog
Published in

Codemi Blog

Text Localization in Go (Golang)

Photo by pixabay.com

Hi everyone! This is my first medium story. Actually, I want to share some experience, though or opinion about technology related with software engineering field, but I didn’t know how to do, or just being lazy :)

So today, I have a topic that I want to share with you, from my experiences expanding some feature on our mobile application. One of them is about language. We have an issue about language that we’re using on our app. Basically, we mostly using English (sometimes mixed with Bahasa) for our text, like menu, title, etc. Then, since we SaaS application and getting high demand from our clients to have another language, we start thinking to make it dynamic.

In this case, I don’t want to talk for the mobile application side, the reason is I’m Backend Developer :) But we realized that it’s not enough to make it done just from mobile application side. Because we did a lot of API calls and sometimes using the messages from backend to show on mobile application.

Using conditional statements are the easiest or common ways to made the messages dynamically from backend (FYI, our backend written in Go Programming Language). For example :

language := "en" // assume we get from client request
message := ""
if language == "en" {
message = "Good morning"
} else if language == "id" {
message = "Selamat pagi"
} else if language == "jp" {
message = "おはようございます"
}

But I think it’s not a good solution, which is having a big effort, unmaintainable and difficult to expand if we want to adding another language.

Then, our goal is made something for solving those issues.

Finally, here is the open source software in Go (https://github.com/moemoe89/go-localization) for transforming the text to a different meaning.

Rather than building the function privately, I prefer share it to everyone as a public library and hope it would be solving the others same issue.

To use this library on your Go program is quite easy. First, install the package with this command :

go get github.com/moemoe89/go-localization 

Make JSON file with contain language code and messages, and save it as JSON file in your project path, maybe named language.json. For example:

Last, import the package, init the config and try the transformation!

With this library, we have some advantages.

  • First, we can easily transform the text with code on our JSON file.
  • Next, you can change the key for the message with code, if you prefer using code as your message id.
  • Last, it wouldn’t break the code if the code or message that you’ve input were not found. By default, the output will be same as the input.

Hope you enjoy it, I’m happy if you have an idea for this library and want to make some Pull Request !

Thank you!

--

--

--

Codemi is Education Technology Startup providing Learning Management System for your business.

Recommended from Medium

10 Lessons Learned from building Engine Yard’s Container Platform on Kubernetes

Kubernetes

A Beginner’s Guide To Structured Query Language: Everything You Need To Know

Brewtiful: Ruby on Rails Project

Configure Hadoop and start cluster services using Ansible Playbook.

Cascade V2, Migration, and Multiplier

Top 10 Web Services To Build Your Own Video Calling App

My journey becoming a Unity game developer: Beginning Cutscene-Polishing the Intro cutscene

My First Sprint Experience

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Bismo Baruno

Bismo Baruno

Software Engineer | Traveler | Guitarist | J-Lovers

More from Medium

Golang: Start 7 web frameworks with same set of codes

gRPC In Go (with MongoDB) — Part 1

Automation — Dynamic sitemap generation with Golang API

Automation — Dynamic sitemap generation with Golang API

Writing Unit Tests with Testify