Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend translation system to Lua modules #347

Closed
Brianetta opened this issue Jul 29, 2011 · 6 comments

Comments

@Brianetta
Copy link
Contributor

commented Jul 29, 2011

We will need:

  • A way for the strings to be defined as being of a given language
    • Perhaps, a way of defining a module's strings in external language files
  • A method for the module to select an appropriate string
    • Should include a mechanism for regular same-language alt-strings
  • Translations into supported languages (currently en and de) for all modules which ship with the game
  • Documentation for Lua coders

I'd suggest that languages are stored in external files (please excuse my sprintf abuse):

"data/modules/lang/%s/%s.txt", module_name, language_name
@Luomu

This comment has been minimized.

Copy link
Member

commented Jul 31, 2011

Slight change:

data/modules/deliverpackage/deliverpackage.lua
data/modules/deliverpackage/lang/english.lua (lua, could be a table)
data/modules/deliverpackage/lang/swahili.lua

Then it's possible to completely add/remove a module by moving one folder.

@Brianetta

This comment has been minimized.

Copy link
Contributor Author

commented Jul 31, 2011

"data/modules/%s/lang/%s.txt", module_name, language_name

Fair enough.

@Luomu

This comment has been minimized.

Copy link
Member

commented Aug 7, 2011

Since we don't need to switch languages at runtime, would this simple system do:

data/libs/Translations.lua:

Translations = {}

--merge tables
function Translations.add(stringtable)
    for k,v in pairs(stringtable) do
        Translations[k] = v
    end
end

--fetch a translated string, could be also _() in gettext style
--if no translation is available, use the key name, fairly noticeable
function L(key)
    if Translations[key] == nil then return key end
    return Translations[key]
end

Each language needs a lua table like this:

--data/modules/PizzaDelivery/lang/english.lua:
local english = {
    Delivery_Greeting = "Yo!",
    Delivery_BB_Description = "Deliver a pizza to {system}",
    Delivery_Failed_Late = "Mission failed: overdue.",
    Delivery_Success = "Excellent! Here's your reward.",
    Delivery_AcceptJob = "I'll take the job.",
}

--add to global translation table
Translations.add(english)

In module itself, use the translate function:

--data/modules/PizzaDelivery/module.lua:
form:SetMessage(L('Delivery_Greeting'))
form:AddOption(L('General_HangUp'), -1) --generic string

The only thing left would be to selectively process the correct language file (now everything with .lua is loaded)

@Brianetta

This comment has been minimized.

Copy link
Contributor Author

commented Aug 7, 2011

We must bear in mind that Lua modules often contain a number of different scripts for the same mission. So, L() would require two arguments: Language, script ID. Script ID could be optional (where the translation function chooses a random script, and then (importantly) sticks to its choice for the whole module instance). The module must have a means of choosing its own script, though; there might be instances where a module is running a script that the author wants to be special; it's worded such that it should only be run the first time, perhaps, or is responding to player actions performed during another module instance's run, or is running as part of a longer narrative.

Failing to the index is a fairly clever way of identifying the untranslated strings, especially when an English fallback might be ambiguous.

@richardpl

This comment has been minimized.

Copy link
Contributor

commented Oct 21, 2011

Can this be closed?

@Brianetta

This comment has been minimized.

Copy link
Contributor Author

commented Oct 21, 2011

Well spotted, that man. It can.

@Brianetta Brianetta closed this Oct 21, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.