Skip to content
/ babel Public

Babel is a set of simple internationalisation tools for LÖVE 2D.

Notifications You must be signed in to change notification settings

TomK32/babel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BABEL

Babel is a set of simple internationalisation tools for LÖVE 2D.

Setting it up

Simply copy babel.lua in your project folder and modify the main.lua file like this :

require "path to babel.lua (without '.lua')"

function love.load()

    babel.init({ locale = "fre-FR" })

end

Use babel

Initialisation

You must initialize babel in love.load().

babel.init()

babel.init() can get a table as argument with the following indexes :

  • locale The locale to use.
  • locales_folders The folders where babel will look for locales files.

Translate text

There is two function to translate text : babel.translate and _ (who is an alias to the first function).

_( "Text to translate" )
-- or
babel.translate( "Text to translate" )

Using variables in translated texts

You can use variables in translations by passing extra parameters to the translate function :

_( "Hello %name%", { name = "your name" } )

You can use as many entries you need in the extra table.

Add locales files on the fly

I fyou need to load other locales files after init(), you can use :

babel.addLocalesFolder( "my other/folder" )

Create and manage locale files

All the translations are stored in a lua file with the name of the locale (for ex. eng-UK.lua or fre-FR.lua. Thoses files are stored in the folder given in babel.init() (or in a translations folder in the same folder than babel.lua if none given).

Structure of a locale file

LANGUAGE = {

    formats = {
        -- Will be available in futur versions
    },

    -- List of all the translations
    translations = {

        -- The key of each element is the text in parameter of babel.translate()
        ['Hello world'] = "Bonjour le monde",
        ['My name is %name%'] = "Mon nom est %name%"

    }

}
return LANGUAGE

About

Babel is a set of simple internationalisation tools for LÖVE 2D.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages