A Godot plugin for importing translation files in JSONH V2 format using JsonhCs.
This plugin requires Godot with C# .NET support.
- Install the JsonhCs NuGet package.
- Install the addon and enable the plugin.
- Build the .NET project.
- Find your desired locale code.
- Create a text file called
{locale_code}.jsonh. For example, English isen.jsonh. - Import the text file as a "JSONH Translation".
- Navigate to
Project Settings > Localization > Translationsand add the text file. Change "All recognized" to "All files" and select the text file. - Add the messages using the syntax below.
Add messages as properties of a root object:
HELLO: "Hello!"
BYE: "Goodbye!"
Add hierarchical messages with objects:
FOOD.CAKE: "Cake"
FOOD.BREAD: "Bread"
FOOD: {
CAKE: "Cake"
BREAD: "Bread"
}
Add indexed messages with arrays:
GREETINGS.0: "Hello"
GREETINGS.1: "Hi"
GREETINGS.2: "Hey"
GREETINGS: [
"Hello"
"Hi"
"Hey"
]
Translate a message:
GREET: "Hello"
using JsonhTranslations;
string Message = "GREET".Tr();Translate and format a message:
COUNT_GOLD: "You have {0} gold."
using JsonhTranslations;
string Message = "COUNT_GOLD".Tr(500);Translate a plural message:
YOU_HAVE_SWORDS: "You have {0} swords."
YOU_HAVE_SWORDS*1: "You have {0} sword."
using JsonhTranslations;
string Message = "YOU_HAVE_SWORDS".TrN("*" + 2);Translate an array of messages:
GREET_OPTIONS: [
"Hello"
"Hi"
"Hey"
]
using JsonhTranslations;
List<string> Messages = "GREET_OPTIONS".TrA(".{0}");Add a translation dynamically:
using JsonhTranslations;
Translation EnglishTranslation = JsonhTranslationsExtensions.CreateTranslationFromFile("en.jsonh");
TranslationServer.AddTranslation(EnglishTranslation);Whether to include the translation file's source code as meta in the translation resource.
This is useful for providing one of your translation files in your game as a template for contributors to provide their own translations.
The source code be accessed with the source_text meta property:
string SourceText = (string)GD.Load<Translation>("res://en.jsonh").GetMeta("source_text", "");