Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/excessive/i18n
Internationalization functions for LÖVE.
https://github.com/excessive/i18n
Last synced: 1 day ago
JSON representation
Internationalization functions for LÖVE.
- Host: GitHub
- URL: https://github.com/excessive/i18n
- Owner: excessive
- License: other
- Created: 2015-08-29T04:34:10.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-08-29T04:34:37.000Z (about 9 years ago)
- Last Synced: 2024-08-02T06:21:39.499Z (3 months ago)
- Language: Lua
- Size: 105 KB
- Stars: 23
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-love2d - i18n - Internationalization library designed to help localize your game. (Utilities)
README
# i18n
Internationalization functions for LÖVE. We might rename it to something more interesting later.
# Specifying a language
It's just a Lua table.
Several real-world examples can be found [here, in our LD33 entry](https://github.com/excessive/ludum-dare-33/tree/master/assets/lang).
```lua
return {
locale = "en",
base = "assets/sounds/en",
quotes = { "\"", "\"" }, -- NYI, but planned. Several languages use different quotes.
strings = {
["main/play"] = { text = "Play", audio = "play.ogg" },
["main/options"] = { text = "Options" },
-- etc
}
}
```# Usage
```lua
local lang = require "i18n"-- load all your language files. the filenames are of no significance.
lang:load("languages/en.lua")-- set default locale if a string is not available in the current one.
-- Note: will not return audio for fallback language (that would be really weird).
lang:set_fallback("en")-- set locale to source data from
lang:set_locale("en")-- translated string, path to audio, and whether the string is from fallback.
-- can also be written as lang:get("key")
lang "main/play" -- => "Play", "assets/sounds/en/play.ogg", false
```