Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7162109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:40:50+00:00 2026-05-28T13:40:50+00:00

I built a Lua web application and it’s become clear that I need to

  • 0

I built a Lua web application and it’s become clear that I need to begin internationalizing (“i18n”) it for my overseas customers.

In Lua, what’s the best way to internationalization my application?

I realize this is a significant undertaking, especially since some of my display is hard coded in HTML templates and some data fields are in my currently US-english oriented database.

Any guidance would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:40:51+00:00Added an answer on May 28, 2026 at 1:40 pm

    Edit: added metatable stuff

    Would someone mind making the example code above a little more clear

    Certainly.

    In one file you define a i18n variable with the following methods:

    local i18n = { locales = {} }
    
    local currentLocale = 'en' -- the default language
    
    function i18n.setLocale(newLocale)
      currentLocale = newLocale
      assert(i18n.locales[currentLocale], ("The locale %q was unknown"):format(newLocale))
    end
    
    local function translate(id)
      local result = i18n.locales[currentLocale][id]
      assert(result, ("The id %q was not found in the current locale (%q)"):format(id, currentLocale)
      return result
    end
    
    i18n.translate = translate
    
    setmetatable(i18n, {__call = function(_,...) return translate(id) end})
    
    return i18n
    

    In the same file, or in other(s), you include the locales you need inside i18n.locales .

    local i18n = require 'i18n' -- remove this line if on the same file as before
    
    i18n.locales.en = {
      helloWorld = "Hello world",
      loginWarning = "You need to be logged in to do that"
    }
    
    i18n.locales.es = {
      helloWorld = "Hola mundo",
      loginWarning = "Debes haber iniciado una sesión para hacer eso"
    }
    ...
    

    Usage:

    local i18n = require 'i18n'
    require 'locales' -- if using a separate file for the locales, require it too
    
    print( i18n.translate('helloWorld') ) -- Hello world
    i18n.setLocale('es')
    -- using i18n() instead of i18n.translate()
    print( i18n('helloWorld') ) -- Hola mundo
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've found some places on the web saying that operators in Lua are overloadable
We built a grant application system for a client. They've now asked for some
I built an application which displays the records from database in the window and
I built a Winform app several months ago that schedules appointments for repair techs.
I built a client server application using posix shared memory and posix unnamed semaphores
I'm building a new game and I need to build a web app to
I may have missed this, but is there a built-in method for serializing/deserializing lua
I'm working in lua, and i need to match 2 parts of a line
How do you debug lua code embedded in a c++ application? From what I
I'm retro-fitting an older vb.net application to bring it into compliance with LUA principles

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.