Tip: Use ChatGPT to Generate Locale Files for Localisation
Save Your Localisation Effort with ChatGPT.
In today’s information age, software developers are likely to encounter localization at some point. For solopreneurs building their own app, considering localization is almost a must.
Let’s see an example first.

Programmers clearly don’t write the login page code twice. A common practice is to use a locale file that stores text keys, with the code referencing these keys. Below is an HTML snippet from the last paragraph of the WhenWise Login page.
<div class='row'>
<div class="col m12 s12" style="font-size: 15px; text-align: center;">
<span class="light"><%= t(:dont_have_an_account) %></span>
<a href="/sign-up" class="green-text"><%= t(:register) %></a>
</div>
</div>
Two locale keys are used: “dont_have_an_account” and “register”. In its English locale file (en-AU.html
), in YAML format (a common choice for locale files):
en-AU:
dont_have_an_account: "Don’t have an account?"
register: "Register"
email: "Email"
password: "Password"
remember_me: "Remember me"
Some might wonder “Isn’t it a lot of effort to translate and keep everything updated for multiple languages?”
Yes, it is, even if you have staff proficient in those foreign languages. Now, it can be a lot easier thanks to ChatGPT and other LLMs.
Generate Japanese Locale
Please note, I didn’t bother to escape the double quotes, as ChatGPT takes care of it.
The Result:
ChatGPT kept the keys intact, only translating the quoted text while maintaining the YAML format. Nice! You can click the “Copy code” link (on the top right) to get the raw text version.
In early versions, ChatGPT only translated the text in the quoted string, for example, it would leave “en-AU:
” unchanged. Now ChatGPT is more intelligent.
To Chinese (by default, it does Simplified): “zh-CN
”
To Traditional Chinese (zh-TW
):
Neat! By the way, the translation for Traditional Chinese is slightly wrong, so it’s worth double-checking your results, but it’s mostly correct so it’s a simple and quick way to get started with localisation.
Related reading: