Locale - A simple localization system for LOVE

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
Posts: 13
Joined: Fri Mar 14, 2014 9:14 am
Location: The Web of Interconnectivity

Locale - A simple localization system for LOVE

Post by MarkSill » Sun Dec 14, 2014 4:59 am

Hello everyone!

While writing my game (that hasn't been released yet), I added in a localization system, and I thought I may as well post it here so that others can use it also.

Usage is pretty easy:

Code: Select all

locale = require "locale"

function love.load()

function love.draw()
    love.graphics.print(locale.getLocalized("text.test"), 10, 10)
I use what I believe is a standard localization file system, where it would look something like this:

Code: Select all

text.hello=This is some more text
If you want to get it from Github, it's here

Here's an example setup in the form of a LOVE file, and also the library itself:
(1.61 KiB) Downloaded 75 times
(786 Bytes) Downloaded 62 times
Heyo, I'm MarkSill. I'm a programmer, and I like chips with salsa.

User avatar
Party member
Posts: 1546
Joined: Fri Mar 07, 2008 1:39 pm

Re: Locale - A simple localization system for LOVE

Post by ivan » Sun Dec 14, 2014 6:56 am

Not a bad start.
Although I believe it could be improved in a few ways.
In terms of the implementation "lib.getLocalized" might be kind of slow.
I would suggest parsing the entire localization file into a lookup table instead of iterating all lines.

Next, you may want to add support for arguments so you can do stuff like:

Code: Select all

-- text.points = Congrats, $1, you just earned $2 points -- English (left to right)
-- text.points = تهاني، 1$ ، لقد ربحت 2$ نقطة فقط -- Arabic (right to left)
sz = lib.getLocaliszed("text.points", "PLAYER", 54)
-- Congrats, PLAYER, you just earned 54 points!
I use a library that is similar to yours:
https://bitbucket.org/itraykov/utils/sr ... ?at=master
Although it's not designed for Love2D (I might port it later on), some of the functionality there you might find useful in particular:

Code: Select all

lang.format = function(sz, ...)
  -- replace flags $1, $2, etc with corresponding arguments
  local n = select('#', ...)
  if n > 0 then
    for i = 1, n do
      local a = select(i, ...)
      sz = string.gsub(sz, "$" .. i, a)
  return sz
Also, be careful with the "string" library since not all of its functionality was designed with UTF8 in mind.

PS. Oh ya, and take a look at my signature if you want to have your game localized. :)

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests