There are some helper class for you to implement localization. For best practices, please see example in paracraft package, which uses
poedit to edit and store localization strings with multi-languages.
Helper class for translation table:
UTF8 encoding should be used where ever possible in your source code or mcml files. Everything returned from NPL is also UTF8 encoded, except for native file path.
Follow following steps:
- Use this class to create a global table
Lto look up for localized text with a primary key.
- When your application start, populate
table Lwith data from your localization files according to current language setting.
- In your script code or mcml UI page files, replace any text “XXX” with
Poeditto scan for all source files and update the localization database file.
- Inform your translator to translate the
*.pofiles into multiple languages and generate
*.mofiles. Or you may just use google translate or other services.
- Iterate above three steps when you insert new text in your source code.
-- Right way local text = format(L"Some text %d times", times)
-- BAD & Wrong Way!!! local text = L"Some text "..times..L" times"
for better translation because different language have different syntax.
Localization GetText Tools¶
To store your language strings, you can use plain table in script or use a third-party tool like Poedit. We have created
Poedit plugin to support NPL code, download the NPLgettext tool here.
In paracraft, there is a command called
/poedit which does the
gettext job automatically.