i18n support for Mudlet scripts

Share your scripts and packages with other Mudlet users.
Post Reply
User avatar
demonnic
Posts: 884
Joined: Sat Dec 05, 2009 3:19 pm

i18n support for Mudlet scripts

Post by demonnic »

I have been working on a website in lua, and needed an internationalization library. I found https://github.com/kikito/i18n.lua and decided others might find it useful, so I repackaged it in a mudlet mpackage. All credit goes to the original author. The full details are available on the github page but a basic rundown:

If you install this package, then given:
Code: [show] | [select all] lua
local translations = {
  en = {
    test = "This is a test",
    emergency = "emergency",
  },
  de = {
    test = "Das ist ein Test",
    emergency = "Notfall",
  }
}

i18n.load(translations)
i18n.setLocale('en-US')
Then you can run
Code: [show] | [select all] lua
cecho(string.format("<blue>(<red>%s<blue>)<reset> %s\n", i18n('emergency'), i18n('test')))
And it will look like this:
Screenshot from 2019-10-03 21-56-13.png
Screenshot from 2019-10-03 21-56-13.png (5.94 KiB) Viewed 7481 times
If you do i18n.setLocale("de") and do it again, it will look like:
Screenshot from 2019-10-03 22-01-29.png
Screenshot from 2019-10-03 22-01-29.png (5.79 KiB) Viewed 7481 times
Attachments
i18n.mpackage
(5.51 KiB) Downloaded 418 times

Post Reply