Skip to content

One file simple Lua library to translate and format text.

License

Notifications You must be signed in to change notification settings

ImagicTheCat/Luang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Luang is the fusion of Lua and Lang, it is a simple library that uses the flexibility of the metatables to access translations.

Look at examples/ to understand the usage.

Getting started

-- lib
local Luang = require("Luang")

-- create Lang object (or "translator")
local tr = Luang()

Lang methods/properties

-- load a dict table to the lang dict (merge into the internal dict)
-- dict: table with sub-tables and strings
tr:load(dict)

-- load a dict table to the lang dict for a specific locale
-- equivalent to tr:load({[locale] = dict})
-- dict: table with sub-tables and strings
-- locale: prefix
tr:loadLocale(locale, dict)

-- lang access property
tr.lang

-- access translation
-- args: table used to replace {keys} with values in the translation string (can be nil)
tr.lang.foo.bar(args)

Example

tr:load({
  foo = {
    bar = "first {1} second {2} test {test}",
    foo = "foo"
  }
})

-- ex: cache foo access for better performances
local foo = tr.lang.foo

print(foo.bar({"1st", "2nd", test = "TEST"})) -- "first 1st second 2nd test TEST"
print(foo.foo()) -- "foo"

About

One file simple Lua library to translate and format text.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages