LG Localization - Grisgram/gml-raptor GitHub Wiki

Introduction

LG comes with a bunch of functions that shall make your life easier, when it comes to localized content.
In general, there are two types of functions:

  • Functions that start with LG_ are end-user-functions and are here for you to be called.
  • Functions that start with two underscores __LG are internal functions and should not be called directly.

In addition, LG offers some #macro definitions that shall help you create better readable code.
They follow the same scheme: Some start with LG_ and are here for you to be used, some are internal and start with __LG.

Macros

Most of the macros available for LG are configuration macros and have their docs directly in the LG_Configuration file. You can find this file in the _GAME_SETUP_ section of the project template.

Configuration macros

Macro Default Description
LG_DEFAULT_LANGUAGE "en" Fallback language. Should contain 100% of all strings.
LG_AUTO_INIT_ON_STARTUP true If true, LG_Init() will be called for you.
LG_ROOT_FOLDER "locale/" Location of the locale files in the included files folder.
An english and german default is included in the project template.
LG_SCRIBBLE_COMPATIBLE true If you use scribble too, leave this true.

Runtime macros

These macros hold valid values after the first run of LG_Init().

Macro Description
LG_AVAIL_LOCALES An array of two-letter-strings holding the available locales in this game.
LG_OS_LANGUAGE The active locale of the underlying operating system.
LG_CURRENT_LOCALE The currently active locale (= strings of this locale are currently loaded).

How to create your locale files

You organize the strings of your game in .json files that follow this naming convention:

locale_<language>.json

So, your english strings are in locale_en.json, your german ones in locale_de.json, spanish in locale_es.json, etc...

The json structure is as simple as possible, it's just key/value pairs and LG will read the entire file recursively.
You can organize the json objects in any way you like.

Here is a part of the default language_en.json file that comes with the project template:

{
	"legal" : {
		"game_name"	: "enter-game-name-here",
		"company"	: "risingdemons.com",
		"copyright" 	: "(c)2022 risingdemons.com",
		"locale_author" : "Haerion aka @Grisgram",
		"developer" 	: "Haerion aka @Grisgram",
	},

	"credits" : {
		"credits_title" : "Credits",
	},
}

You can create as many json objects (or groups, if you prefer that name) as you like. More complex games will likely have more group levels. Feel free to cascade as deep as you want, LG can handle it!

Find all details about how to use, access, and resolve the strings from the json files in The LG(...) Function, or go to Other LG Functions for all other functions LG has to offer.

⚠️ **GitHub.com Fallback** ⚠️