Skip to content

jsonh-org/JsonhTranslations

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSONH Translations for Godot 4x

A Godot plugin for importing translation files in JSONH V2 format using JsonhCs.

This plugin requires Godot with C# .NET support.

Setup

  1. Install the JsonhCs NuGet package.
  2. Install the addon and enable the plugin.
  3. Build the .NET project.
  4. Find your desired locale code.
  5. Create a text file called {locale_code}.jsonh. For example, English is en.jsonh.
  6. Import the text file as a "JSONH Translation".
  7. Navigate to Project Settings > Localization > Translations and add the text file. Change "All recognized" to "All files" and select the text file.
  8. Add the messages using the syntax below.

Syntax

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"
]

Methods

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);

Import Options

Output Source Text

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", "");

About

JSON for Humans as a translation file importer in Godot.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Contributors

Languages