Lang - is a module for working with localization in Defold. It provides a way to load and use different languages files in your project.
- 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
Open your game.project
file and add the following line to the dependencies field under the project section:
https://github.com/Insality/defold-lang/archive/refs/tags/2.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.
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 |
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.
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).
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"
}
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()
Read the API Reference file to see the full API documentation for the module.
Read the Use Cases file to see several examples of how to use the this module in your Defold game development projects.
Read the FAQ file to see the answers to frequently asked questions about the module.
This project is licensed under the MIT License - see the LICENSE file for details.
For any issues, questions, or suggestions, please create an issue.
Changelog
- Initial release
Changelog
- Add Defold Editor Script to collect unique characters from selected JSON files
Your donation helps me stay engaged in creating valuable projects for Defold. If you appreciate what I'm doing, please consider supporting me!