Insality / defold-lang

Defold Localization Helper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GitHub release (latest by date) GitHub Workflow Status codecov

Github-sponsors Ko-Fi BuyMeACoffee

Lang

Lang - is a module for working with localization in Defold. It provides a way to load and use different languages files in your project.

Features

  • Handy API - Simple and easy to use API
  • Text Support - Load and use different JSON languages files
  • Saver Support - Save current selected language in Defold-Saver
  • Druid Support - Easy Druid integration

Setup

Open your game.project file and add the following line to the dependencies field under the project section:

Lang v1

https://github.com/Insality/defold-lang/archive/refs/tags/1.zip

After that, select Project ▸ Fetch Libraries to update library dependencies. This happens automatically whenever you open a project so you will only need to do this if the dependencies change without re-opening the project.

Library Size

Note: The library size is calculated based on the build report per platform

Platform Library Size
HTML5 1.80 KB
Desktop / Mobile 2.82 KB

Configuration

You should configure the Lang module in the game.project file:

[lang]
path = /resources/lang
langs = en,ru,es
default = en

This configuration section for game.project defines various settings:

  • path: The path to the directory with language files. Default is /resources/lang. The module will search for language files in this directory by the language name.
  • langs: A list of available languages. Default is en.
  • default: The default language. Default is en.

The module uses sys.load_resource to load the files. Place your files inside your custom resources folder to ensure they are included in the build.

Default Language

The default language in settings is used as a fallback. By default, Defold Lang tries to load the user device language, acquired by sys.get_sys_info().device_language. If the language is not found in the available languages, the default language is used. Defold uses the two-character ISO-639 format for language codes ("en", "ru", "es", etc).

Localization Files

Create a directory with language files in the path directory. The module will search for language files in this directory by the language name.

The lang file - is a JSON file with the simple key-value structure. The key is the language id, and the value is the text for this language id.

Example of the lang file:

{
	"ui_hello_world": "Hello, World!",
	"ui_hello_name", "Hello, %s!"
	"ui_settings": "Settings",
	"ui_exit": "Exit"
}

API Reference

Quick API Reference

lang.init()
lang.set_lang(lang_id)
lang.get_lang()
lang.get_langs()
lang.set_next_lang()
lang.txt(text_id)
lang.txp(text_id, ...)
lang.txr(text_id)
lang.is_exist(text_id)
lang.set_logger([logger])
lang.reset_state()

API Reference

Read the API Reference file to see the full API documentation for the module.

Use Cases

Read the Use Cases file to see several examples of how to use the this module in your Defold game development projects.

FAQ

Read the FAQ file to see the answers to frequently asked questions about the module.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Issues and Suggestions

For any issues, questions, or suggestions, please create an issue.

👏 Contributors

❤️ Support project ❤️

Your donation helps me stay engaged in creating valuable projects for Defold. If you appreciate what I'm doing, please consider supporting me!

Github-sponsors Ko-Fi BuyMeACoffee

About

Defold Localization Helper

License:MIT License


Languages

Language:Lua 100.0%