I’ve been working on a game that required localization. So I started out a few months ago making something that worked but was hardcoded for the game I was working on. Despite that, it was a LOT easier than I thought because Godot makes it really easy. (Localization is simply the process of making your game playable in another country. For most games that typically means translation of game text into other languages.)
So yesterday I decided to pull that functionality out and turn it into its own addon/plugin. I added step-by-step instructions in the Readme on how to not only use it, but how to actually use Google Sheets to create the translations for you, because that’s the real bottleneck in localization. Once you setup your spreadsheet, it’s literally click-and-drag to make new translations. I also handle a number of gotchas.
The addon is lightweight, containing an Autoload and an OptionButton. The Autoload does some heavy lifting for you, including saving and loading the language/locale your player picks, and hooking up all localized languages and countries for you.
The LocalizationButton class is an OptionButton that automatically loads up an option for every language and locale you’ve loaded, and presents a country flag for each. The button is configurable, and can show the flag in 5 different sizes. It can display no text, the language code, the country code, the language name, the country name; and all that can be easily localized (I show you how in the Readme). Additionally the button allows you to automatically size the button’s text with the flag size you choose.
An example/test project is included in the repo.
If anyone wants to try it out and give me feedback, I’d appreciate it.
Great work as usual, and well described. I opened 2 issues on GitHub for your consideration after a short test session.
It’s an interesting coincidence, because I have just implemented localization into my project 2 days ago, which resulted in an almost identical outcome, just a little less customizable than yours, and rather based on the gettext instead of CSV (but with the 4.6 localization changes coming in I will probably switch to CSV as well).
If you released it 3 days ago, I would probably just copy over your solution again
It’s on me, true. I’ll bother you with every planned feature from now on
There’s currently no support for context and multiple plural forms in CSV. For most languages that’s not a big deal, but I’m Polish, speaking a language that has multiple plural forms. Therefore, proper translation to Polish (which is always the first translation I do right after English) usually requires gettext, so I just learnt to work with gettext.
This will change with 4.6 as mentioned in the 4.6 beta 1 snapshot, so I’m looking forward to converting my translation workflows to the simpler CSV.
I even wrote a plugin CSV to gettext converter not too long ago that allows conversion from gettext to CSV and vice versa. It will come very handy once the 4.6 rolls out .
I mean, I can always say no, but I have a lot of little things I haven’t really made public. I’m sure you’ve noticed I tend to turn features into plugins so I can re-use them. This one had been sitting there and yesterday I just thought it’d be fun to tackle.
Some of the other things I haven’t mentioned much here…
Camera3D - A plugin that supports multiple camera angles for 3D including first person and 3rd-person follow, bird’s eye view, isometric view, and allows you to add your own cameras in the rotation by just adding a new camera node. (It’s what I used for Skele-Tom. I just disabled the switch camera button and called the cameras with candies.)
ChibiAnimatedSprite2D - A plugin that adds a single node type to load and animate all the CraftPix Chibi Sprites which I came across doing lessons from GameDev.tv. (The code I did for this made developing the Localization plugin a lot faster.)
CurvedTerrain2D - A plugin that adds a curved terrain node using tiles you’d normally use in a TileMap2D for side-scrollers.
SlidingPanel - A sliding panel UI demo I did for fun to answer a question last week that I might turn into a plugin.
Platformer Switch - Another demo I did for fun that I thought about turning into a plugin that includes an elevator, windmill, and other AnimatableBody2D objects that are commonly used in platformers. And maybe pickups too, like a bouncing coin pickup
A scrolling number display I started working on to answer a question and then gave it up cause I was spending too much time on it.
A curved text plugin I got working as a Node2D, but not for a Control so I never uploaded it.
A Character2D plugin that I use for my games but haven’t uploaded yet.
A raycasting interaction component for 3D I developed but never did anything with.
Plus some others I probably forgot about or never got pulled into their own components.
Out of curiosity, could you add a Polish translation, delete the configuration.settings file in app_userdata for the project and see if it defaults to polish for you? There’s an OS locale detection Godot has that I called and I’m curious if it works.
It does work if I add the pl translation, but doesn’t work if I add pl_PL translation.
You’re using OS.get_locale_language() here:
if current_selection == -1:
var preferred_language: String = OS.get_locale_language()
which gets just the pl, so the pl_PL won’t be matched.
print(OS.get_locale_language()) ## prints "pl"
print(OS.get_locale()) ## prints "pl_PL"
Maybe you could first check if there is a full locale match and only after that fallback to locale_language.
I saw some of these already, but haven’t had a chance to play around with them properly other than the StateMachine. I’ll definitely need to have a look at this repertoire some time